|
| 1 | +require "spec_helper" |
| 2 | + |
| 3 | +module LaunchDarkly |
| 4 | + module Impl |
| 5 | + module DataStore |
| 6 | + describe DataKind do |
| 7 | + describe "eql?" do |
| 8 | + it "constant instances are equal to themselves" do |
| 9 | + expect(LaunchDarkly::FEATURES.eql?(LaunchDarkly::FEATURES)).to be true |
| 10 | + expect(LaunchDarkly::SEGMENTS.eql?(LaunchDarkly::SEGMENTS)).to be true |
| 11 | + end |
| 12 | + |
| 13 | + it "same constructions are equal" do |
| 14 | + expect(LaunchDarkly::FEATURES.eql?(DataKind.new(namespace: "features", priority: 1))).to be true |
| 15 | + expect(DataKind.new(namespace: "features", priority: 1).eql?(DataKind.new(namespace: "features", priority: 1))).to be true |
| 16 | + |
| 17 | + expect(LaunchDarkly::SEGMENTS.eql?(DataKind.new(namespace: "segments", priority: 0))).to be true |
| 18 | + expect(DataKind.new(namespace: "segments", priority: 0).eql?(DataKind.new(namespace: "segments", priority: 0))).to be true |
| 19 | + end |
| 20 | + |
| 21 | + it "distinct namespaces are not equal" do |
| 22 | + expect(DataKind.new(namespace: "features", priority: 1).eql?(DataKind.new(namespace: "segments", priority: 1))).to be false |
| 23 | + end |
| 24 | + |
| 25 | + it "distinct priorities are not equal" do |
| 26 | + expect(DataKind.new(namespace: "features", priority: 1).eql?(DataKind.new(namespace: "features", priority: 2))).to be false |
| 27 | + expect(DataKind.new(namespace: "segments", priority: 1).eql?(DataKind.new(namespace: "segments", priority: 2))).to be false |
| 28 | + end |
| 29 | + |
| 30 | + it "handles non-DataKind objects" do |
| 31 | + ["example", true, 1, 1.0, [], {}].each do |obj| |
| 32 | + expect(LaunchDarkly::FEATURES.eql?(obj)).to be false |
| 33 | + end |
| 34 | + end |
| 35 | + end |
| 36 | + |
| 37 | + describe "hash" do |
| 38 | + it "constant instances are equal to themselves" do |
| 39 | + expect(LaunchDarkly::FEATURES.hash).to be LaunchDarkly::FEATURES.hash |
| 40 | + expect(LaunchDarkly::SEGMENTS.hash).to be LaunchDarkly::SEGMENTS.hash |
| 41 | + end |
| 42 | + |
| 43 | + it "same constructions are equal" do |
| 44 | + expect(LaunchDarkly::FEATURES.hash).to be DataKind.new(namespace: "features", priority: 1).hash |
| 45 | + expect(DataKind.new(namespace: "features", priority: 1).hash).to be DataKind.new(namespace: "features", priority: 1).hash |
| 46 | + |
| 47 | + expect(LaunchDarkly::SEGMENTS.hash).to be DataKind.new(namespace: "segments", priority: 0).hash |
| 48 | + expect(DataKind.new(namespace: "segments", priority: 0).hash).to be DataKind.new(namespace: "segments", priority: 0).hash |
| 49 | + end |
| 50 | + |
| 51 | + it "distinct namespaces are not equal" do |
| 52 | + expect(DataKind.new(namespace: "features", priority: 1).hash).not_to be DataKind.new(namespace: "segments", priority: 1).hash |
| 53 | + end |
| 54 | + |
| 55 | + it "distinct priorities are not equal" do |
| 56 | + expect(DataKind.new(namespace: "features", priority: 1).hash).not_to be DataKind.new(namespace: "features", priority: 2).hash |
| 57 | + expect(DataKind.new(namespace: "segments", priority: 1).hash).not_to be DataKind.new(namespace: "segments", priority: 2).hash |
| 58 | + end |
| 59 | + end |
| 60 | + end |
| 61 | + end |
| 62 | + end |
| 63 | +end |
0 commit comments