@quenty/observablecollection 12.19.4 → 12.20.0-canary.544.de8fcee.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -2
- package/package.json +15 -15
- package/src/Shared/ObservableCountingMap.spec.lua +32 -29
- package/src/Shared/ObservableList.spec.lua +92 -88
- package/src/Shared/ObservableMap.spec.lua +51 -48
- package/src/Shared/ObservableMapList.spec.lua +16 -13
- package/src/Shared/SortedList/ObservableSortedList.spec.lua +36 -33
package/CHANGELOG.md
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
# [12.20.0-canary.544.de8fcee.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/observablecollection@12.19.3...@quenty/observablecollection@12.20.0-canary.544.de8fcee.0) (2025-04-01)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Fix existing tests ([655787c](https://github.com/Quenty/NevermoreEngine/commit/655787ced1139136e12f81800e229aa076731561))
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/observablecollection",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.20.0-canary.544.de8fcee.0",
|
|
4
4
|
"description": "A set of observable collections, such as sets, maps, sorted lists, and more.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -27,24 +27,24 @@
|
|
|
27
27
|
"Quenty"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@quenty/baseobject": "
|
|
31
|
-
"@quenty/brio": "
|
|
32
|
-
"@quenty/ducktype": "
|
|
33
|
-
"@quenty/loader": "
|
|
34
|
-
"@quenty/maid": "
|
|
35
|
-
"@quenty/promise": "
|
|
36
|
-
"@quenty/rx": "
|
|
37
|
-
"@quenty/signal": "
|
|
38
|
-
"@quenty/steputils": "
|
|
39
|
-
"@quenty/symbol": "
|
|
40
|
-
"@quenty/table": "
|
|
41
|
-
"@quenty/valueobject": "
|
|
30
|
+
"@quenty/baseobject": "10.8.0",
|
|
31
|
+
"@quenty/brio": "14.17.0-canary.544.de8fcee.0",
|
|
32
|
+
"@quenty/ducktype": "5.8.1",
|
|
33
|
+
"@quenty/loader": "10.8.0",
|
|
34
|
+
"@quenty/maid": "3.4.0",
|
|
35
|
+
"@quenty/promise": "10.10.1",
|
|
36
|
+
"@quenty/rx": "13.17.0-canary.544.de8fcee.0",
|
|
37
|
+
"@quenty/signal": "7.10.0",
|
|
38
|
+
"@quenty/steputils": "3.5.3",
|
|
39
|
+
"@quenty/symbol": "3.4.0",
|
|
40
|
+
"@quenty/table": "3.7.1",
|
|
41
|
+
"@quenty/valueobject": "13.17.0-canary.544.de8fcee.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@quenty/blend": "
|
|
44
|
+
"@quenty/blend": "12.18.0-canary.544.de8fcee.0"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "de8fcee995fcdae464964357b4c770c03f4c7e03"
|
|
50
50
|
}
|
|
@@ -4,35 +4,38 @@
|
|
|
4
4
|
|
|
5
5
|
local require = require(game:GetService("ServerScriptService"):FindFirstChild("LoaderUtils", true).Parent).bootstrapStory(script)
|
|
6
6
|
|
|
7
|
+
local Jest = require("Jest")
|
|
7
8
|
local ObservableCountingMap = require("ObservableCountingMap")
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
10
|
+
local describe = Jest.Globals.describe
|
|
11
|
+
local expect = Jest.Globals.expect
|
|
12
|
+
local it = Jest.Globals.it
|
|
13
|
+
|
|
14
|
+
describe("ObservableCountingMap.new()", function()
|
|
15
|
+
local observableCountingMap = ObservableCountingMap.new()
|
|
16
|
+
|
|
17
|
+
it("should return 0 for unset values", function()
|
|
18
|
+
expect(observableCountingMap:Get("a")).toEqual(0)
|
|
19
|
+
expect(observableCountingMap:GetTotalKeyCount()).toEqual(0)
|
|
20
|
+
end)
|
|
21
|
+
|
|
22
|
+
it("should allow you to add to a value", function()
|
|
23
|
+
expect(observableCountingMap:Get("a")).toEqual(0)
|
|
24
|
+
expect(observableCountingMap:GetTotalKeyCount()).toEqual(0)
|
|
25
|
+
observableCountingMap:Add("a", 5)
|
|
26
|
+
expect(observableCountingMap:Get("a")).toEqual(5)
|
|
27
|
+
expect(observableCountingMap:GetTotalKeyCount()).toEqual(1)
|
|
28
|
+
end)
|
|
29
|
+
|
|
30
|
+
it("should allow you to add to a value that is already defined", function()
|
|
31
|
+
expect(observableCountingMap:Get("a")).toEqual(5)
|
|
32
|
+
expect(observableCountingMap:GetTotalKeyCount()).toEqual(1)
|
|
33
|
+
observableCountingMap:Add("a", 5)
|
|
34
|
+
expect(observableCountingMap:Get("a")).toEqual(10)
|
|
35
|
+
expect(observableCountingMap:GetTotalKeyCount()).toEqual(1)
|
|
36
|
+
end)
|
|
37
|
+
|
|
38
|
+
it("should clean up", function()
|
|
39
|
+
observableCountingMap:Destroy()
|
|
37
40
|
end)
|
|
38
|
-
end
|
|
41
|
+
end)
|
|
@@ -4,127 +4,131 @@
|
|
|
4
4
|
|
|
5
5
|
local require = require(game:GetService("ServerScriptService"):FindFirstChild("LoaderUtils", true).Parent).bootstrapStory(script)
|
|
6
6
|
|
|
7
|
+
local Jest = require("Jest")
|
|
7
8
|
local ObservableList = require("ObservableList")
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
local describe = Jest.Globals.describe
|
|
11
|
+
local expect = Jest.Globals.expect
|
|
12
|
+
local it = Jest.Globals.it
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
end)
|
|
14
|
+
describe("ObservableList.new()", function()
|
|
15
|
+
local observableList = ObservableList.new()
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
it("should return nil for unset values", function()
|
|
18
|
+
expect(observableList:Get(1)).toEqual(nil)
|
|
19
|
+
end)
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
it("should allow inserting an value", function()
|
|
22
|
+
expect(observableList:GetCount()).toEqual(0)
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
expect(observableList:GetCount()).to.equal(1)
|
|
24
|
-
end)
|
|
24
|
+
observableList:Add("a")
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
end)
|
|
26
|
+
expect(observableList:Get(1)).toEqual("a")
|
|
27
|
+
expect(observableList:GetCount()).toEqual(1)
|
|
28
|
+
end)
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
end)
|
|
30
|
+
it("should allow negative queries", function()
|
|
31
|
+
expect(observableList:Get(-1)).toEqual("a")
|
|
32
|
+
expect(observableList:Get(-2)).toEqual(nil)
|
|
33
|
+
end)
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
it("should allow false as a value", function()
|
|
36
|
+
expect(observableList:Get(2)).toEqual(nil)
|
|
37
|
+
observableList:Add(false)
|
|
38
|
+
expect(observableList:Get(2)).toEqual(false)
|
|
39
|
+
end)
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
it("should allow negative queries after false", function()
|
|
42
|
+
expect(observableList:Get(1)).toEqual("a")
|
|
43
|
+
expect(observableList:Get(2)).toEqual(false)
|
|
44
|
+
|
|
45
|
+
expect(observableList:Get(-1)).toEqual(false)
|
|
46
|
+
expect(observableList:Get(-2)).toEqual("a")
|
|
47
|
+
end)
|
|
48
|
+
|
|
49
|
+
it("should fire off events for a specific key", function()
|
|
50
|
+
local seen = {}
|
|
51
|
+
local sub = observableList:ObserveIndex(1):Subscribe(function(value)
|
|
52
|
+
table.insert(seen, value)
|
|
43
53
|
end)
|
|
54
|
+
observableList:InsertAt("c", 1)
|
|
44
55
|
|
|
45
|
-
|
|
46
|
-
local seen = {}
|
|
47
|
-
local sub = observableList:ObserveIndex(1):Subscribe(function(value)
|
|
48
|
-
table.insert(seen, value)
|
|
49
|
-
end)
|
|
50
|
-
observableList:InsertAt("c", 1)
|
|
56
|
+
sub:Destroy()
|
|
51
57
|
|
|
52
|
-
|
|
58
|
+
expect(#seen).toEqual(2)
|
|
59
|
+
expect(seen[1]).toEqual(1)
|
|
60
|
+
expect(seen[2]).toEqual(2)
|
|
61
|
+
end)
|
|
53
62
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
63
|
+
it("should fire off events for all keys", function()
|
|
64
|
+
local seen = {}
|
|
65
|
+
local sub = observableList:ObserveItemsBrio():Subscribe(function(value)
|
|
66
|
+
table.insert(seen, value)
|
|
57
67
|
end)
|
|
68
|
+
observableList:Add("a")
|
|
58
69
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
end)
|
|
64
|
-
observableList:Add("a")
|
|
70
|
+
local value = seen[4]:GetValue()
|
|
71
|
+
expect(#seen).toEqual(4)
|
|
72
|
+
expect(value).toEqual("a")
|
|
73
|
+
expect(seen[4]:IsDead()).toEqual(false)
|
|
65
74
|
|
|
66
|
-
|
|
67
|
-
expect(seen[4]:GetValue()).to.equal("a")
|
|
68
|
-
expect(seen[4]:IsDead()).to.equal(false)
|
|
75
|
+
sub:Destroy()
|
|
69
76
|
|
|
70
|
-
|
|
77
|
+
expect(#seen).toEqual(4)
|
|
78
|
+
expect(seen[4]:IsDead()).toEqual(true)
|
|
79
|
+
end)
|
|
71
80
|
|
|
72
|
-
|
|
73
|
-
|
|
81
|
+
it("it should be able to observe a specific key", function()
|
|
82
|
+
local seen = {}
|
|
83
|
+
local sub = observableList:ObserveAtIndex(1):Subscribe(function(value)
|
|
84
|
+
table.insert(seen, value)
|
|
74
85
|
end)
|
|
75
86
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
local sub = observableList:ObserveAtIndex(1):Subscribe(function(value)
|
|
79
|
-
table.insert(seen, value)
|
|
80
|
-
end)
|
|
87
|
+
local originalList = observableList:GetList()
|
|
88
|
+
expect(originalList[1]).toEqual("c")
|
|
81
89
|
|
|
82
|
-
|
|
83
|
-
expect(originalList[1]).to.equal("c")
|
|
90
|
+
observableList:InsertAt("dragon", 1)
|
|
84
91
|
|
|
85
|
-
|
|
92
|
+
sub:Destroy()
|
|
86
93
|
|
|
87
|
-
|
|
94
|
+
expect(#seen).toEqual(2)
|
|
95
|
+
expect(seen[1]).toEqual("c")
|
|
96
|
+
expect(seen[2]).toEqual("dragon")
|
|
97
|
+
end)
|
|
88
98
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
99
|
+
it("it should be able to observe a specific negative key", function()
|
|
100
|
+
local seen = {}
|
|
101
|
+
local sub = observableList:ObserveAtIndex(-1):Subscribe(function(value)
|
|
102
|
+
table.insert(seen, value)
|
|
92
103
|
end)
|
|
93
104
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
local sub = observableList:ObserveAtIndex(-1):Subscribe(function(value)
|
|
97
|
-
table.insert(seen, value)
|
|
98
|
-
end)
|
|
105
|
+
local originalList = observableList:GetList()
|
|
106
|
+
expect(originalList[#originalList]).toEqual("a")
|
|
99
107
|
|
|
100
|
-
|
|
101
|
-
expect(originalList[#originalList]).to.equal("a")
|
|
108
|
+
observableList:Add("fire")
|
|
102
109
|
|
|
103
|
-
|
|
110
|
+
sub:Destroy()
|
|
104
111
|
|
|
105
|
-
|
|
112
|
+
expect(#seen).toEqual(2)
|
|
113
|
+
expect(seen[1]).toEqual("a")
|
|
114
|
+
expect(seen[2]).toEqual("fire")
|
|
115
|
+
end)
|
|
106
116
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
117
|
+
it("should fire off events on removal", function()
|
|
118
|
+
local seen = {}
|
|
119
|
+
local sub = observableList:ObserveIndex(2):Subscribe(function(value)
|
|
120
|
+
table.insert(seen, value)
|
|
110
121
|
end)
|
|
122
|
+
observableList:RemoveAt(1)
|
|
111
123
|
|
|
112
|
-
|
|
113
|
-
local seen = {}
|
|
114
|
-
local sub = observableList:ObserveIndex(2):Subscribe(function(value)
|
|
115
|
-
table.insert(seen, value)
|
|
116
|
-
end)
|
|
117
|
-
observableList:RemoveAt(1)
|
|
124
|
+
sub:Destroy()
|
|
118
125
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
expect(seen[2]).to.equal(1)
|
|
124
|
-
end)
|
|
126
|
+
expect(#seen).toEqual(2)
|
|
127
|
+
expect(seen[1]).toEqual(2)
|
|
128
|
+
expect(seen[2]).toEqual(1)
|
|
129
|
+
end)
|
|
125
130
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
end)
|
|
131
|
+
it("should clean up", function()
|
|
132
|
+
observableList:Destroy()
|
|
129
133
|
end)
|
|
130
|
-
end
|
|
134
|
+
end)
|
|
@@ -4,71 +4,74 @@
|
|
|
4
4
|
|
|
5
5
|
local require = require(game:GetService("ServerScriptService"):FindFirstChild("LoaderUtils", true).Parent).bootstrapStory(script)
|
|
6
6
|
|
|
7
|
+
local Jest = require("Jest")
|
|
7
8
|
local ObservableMap = require("ObservableMap")
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
local describe = Jest.Globals.describe
|
|
11
|
+
local expect = Jest.Globals.expect
|
|
12
|
+
local it = Jest.Globals.it
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
end)
|
|
14
|
+
describe("ObservableMap.new()", function()
|
|
15
|
+
local observableMap = ObservableMap.new()
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
it("should return nil for unset values", function()
|
|
18
|
+
expect(observableMap:Get("a")).toEqual(nil)
|
|
19
|
+
end)
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
it("should allow setting a value", function()
|
|
22
|
+
expect(observableMap:GetCount()).toEqual(0)
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
expect(observableMap:GetCount()).to.equal(1)
|
|
24
|
-
end)
|
|
24
|
+
observableMap:Set("a", "Hello World")
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
expect(observableMap:Get("a")).toEqual("Hello World")
|
|
27
|
+
expect(observableMap:GetCount()).toEqual(1)
|
|
28
|
+
end)
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
it("should overwrite values", function()
|
|
31
|
+
expect(observableMap:Get("a")).toEqual("Hello World")
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
observableMap:Set("a", "Hello World 2")
|
|
34
|
+
|
|
35
|
+
expect(observableMap:Get("a")).toEqual("Hello World 2")
|
|
36
|
+
end)
|
|
33
37
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
it("should allow false as a key", function()
|
|
39
|
+
expect(observableMap:Get(false)).toEqual(nil)
|
|
40
|
+
observableMap:Set(false, "Hello")
|
|
41
|
+
expect(observableMap:Get(false)).toEqual("Hello")
|
|
42
|
+
end)
|
|
43
|
+
|
|
44
|
+
it("should fire off events for a specific key", function()
|
|
45
|
+
local seen = {}
|
|
46
|
+
local sub = observableMap:ObserveValueForKey("c"):Subscribe(function(value)
|
|
47
|
+
table.insert(seen, value)
|
|
38
48
|
end)
|
|
49
|
+
observableMap:Set("c", "Hello")
|
|
39
50
|
|
|
40
|
-
|
|
41
|
-
local seen = {}
|
|
42
|
-
local sub = observableMap:ObserveValueForKey("c"):Subscribe(function(value)
|
|
43
|
-
table.insert(seen, value)
|
|
44
|
-
end)
|
|
45
|
-
observableMap:Set("c", "Hello")
|
|
51
|
+
sub:Destroy()
|
|
46
52
|
|
|
47
|
-
|
|
53
|
+
expect(#seen).toEqual(1)
|
|
54
|
+
expect(seen[1]).toEqual("Hello")
|
|
55
|
+
end)
|
|
48
56
|
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
it("should fire off events for all keys", function()
|
|
58
|
+
local seen = {}
|
|
59
|
+
local sub = observableMap:ObserveValuesBrio():Subscribe(function(value)
|
|
60
|
+
table.insert(seen, value)
|
|
51
61
|
end)
|
|
62
|
+
observableMap:Set("d", "Hello")
|
|
52
63
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
table.insert(seen, value)
|
|
57
|
-
end)
|
|
58
|
-
observableMap:Set("d", "Hello")
|
|
59
|
-
|
|
60
|
-
expect(#seen).to.equal(4)
|
|
61
|
-
expect(seen[4]:GetValue()).to.equal("Hello")
|
|
62
|
-
expect(seen[4]:IsDead()).to.equal(false)
|
|
64
|
+
expect(#seen).toEqual(4)
|
|
65
|
+
expect(seen[4]:GetValue()).toEqual("Hello")
|
|
66
|
+
expect(seen[4]:IsDead()).toEqual(false)
|
|
63
67
|
|
|
64
|
-
|
|
68
|
+
sub:Destroy()
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
expect(#seen).toEqual(4)
|
|
71
|
+
expect(seen[4]:IsDead()).toEqual(true)
|
|
72
|
+
end)
|
|
69
73
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
end)
|
|
74
|
+
it("should clean up", function()
|
|
75
|
+
observableMap:Destroy()
|
|
73
76
|
end)
|
|
74
|
-
end
|
|
77
|
+
end)
|
|
@@ -4,21 +4,24 @@
|
|
|
4
4
|
|
|
5
5
|
local require = require(game:GetService("ServerScriptService"):FindFirstChild("LoaderUtils", true).Parent).bootstrapStory(script)
|
|
6
6
|
|
|
7
|
+
local Jest = require("Jest")
|
|
7
8
|
local ObservableMapList = require("ObservableMapList")
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
local describe = Jest.Globals.describe
|
|
11
|
+
local expect = Jest.Globals.expect
|
|
12
|
+
local it = Jest.Globals.it
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
end)
|
|
14
|
+
describe("ObservableMapList.new()", function()
|
|
15
|
+
local observableMapList = ObservableMapList.new()
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
expect(observableMapList:GetAtListIndex("dragon", 1)).to.equal("hello")
|
|
20
|
-
expect(observableMapList:GetAtListIndex("dragon", -1)).to.equal("hello")
|
|
21
|
-
expect(observableMapList:GetAtListIndex("fire", 1)).to.equal(nil)
|
|
22
|
-
end)
|
|
17
|
+
it("should return nil for unset values", function()
|
|
18
|
+
expect(observableMapList:GetAtListIndex("dragon", 1)).toEqual(nil)
|
|
23
19
|
end)
|
|
24
|
-
|
|
20
|
+
|
|
21
|
+
it("should allow additions", function()
|
|
22
|
+
observableMapList:Push("hello", "dragon")
|
|
23
|
+
expect(observableMapList:GetAtListIndex("hello", 1)).toEqual("dragon")
|
|
24
|
+
expect(observableMapList:GetAtListIndex("hello", -1)).toEqual("dragon")
|
|
25
|
+
expect(observableMapList:GetAtListIndex("fire", 1)).toEqual(nil)
|
|
26
|
+
end)
|
|
27
|
+
end)
|
|
@@ -4,53 +4,56 @@
|
|
|
4
4
|
|
|
5
5
|
local require = require(game:GetService("ServerScriptService"):FindFirstChild("LoaderUtils", true).Parent).bootstrapStory(script)
|
|
6
6
|
|
|
7
|
+
local Jest = require("Jest")
|
|
7
8
|
local ObservableSortedList = require("ObservableSortedList")
|
|
8
9
|
local Rx = require("Rx")
|
|
9
10
|
local StepUtils = require("StepUtils")
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
local describe = Jest.Globals.describe
|
|
13
|
+
local expect = Jest.Globals.expect
|
|
14
|
+
local it = Jest.Globals.it
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
end)
|
|
16
|
+
describe("ObservableSortedList.new()", function()
|
|
17
|
+
local observableSortedList = ObservableSortedList.new()
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
it("should return nil for unset values", function()
|
|
20
|
+
expect(observableSortedList:Get(1)).toEqual(nil)
|
|
21
|
+
end)
|
|
22
|
+
|
|
23
|
+
it("should allow inserting an value", function()
|
|
24
|
+
expect(observableSortedList:GetCount()).toEqual(0)
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
observableSortedList:Add("b", Rx.of("b"))
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
StepUtils.deferWait()
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
expect(observableSortedList:Get(1)).toEqual("b")
|
|
31
|
+
expect(observableSortedList:GetCount()).toEqual(1)
|
|
32
|
+
end)
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
it("should sort the items", function()
|
|
35
|
+
expect(observableSortedList:GetCount()).toEqual(1)
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
observableSortedList:Add("a", Rx.of("a"))
|
|
34
38
|
|
|
35
|
-
|
|
39
|
+
StepUtils.deferWait()
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
expect(observableSortedList:Get(1)).toEqual("a")
|
|
42
|
+
expect(observableSortedList:Get(2)).toEqual("b")
|
|
43
|
+
expect(observableSortedList:GetCount()).toEqual(2)
|
|
44
|
+
end)
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
it("should add in order if number is the same", function()
|
|
47
|
+
observableSortedList = ObservableSortedList.new()
|
|
48
|
+
observableSortedList:Add("a", Rx.of(0))
|
|
49
|
+
observableSortedList:Add("b", Rx.of(0))
|
|
50
|
+
observableSortedList:Add("c", Rx.of(0))
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
StepUtils.deferWait()
|
|
49
53
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
end)
|
|
54
|
+
expect(observableSortedList:Get(1)).toEqual("a")
|
|
55
|
+
expect(observableSortedList:Get(2)).toEqual("b")
|
|
56
|
+
expect(observableSortedList:Get(3)).toEqual("c")
|
|
57
|
+
expect(observableSortedList:GetCount()).toEqual(3)
|
|
55
58
|
end)
|
|
56
|
-
end
|
|
59
|
+
end)
|