• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mattonem / PharoJS / 13788456566

11 Mar 2025 12:50PM UTC coverage: 62.432% (+4.5%) from 57.928%
13788456566

push

github

mattonem
typo

1 of 1 new or added line in 1 file covered. (100.0%)

63 existing lines in 4 files now uncovered.

13233 of 21196 relevant lines covered (62.43%)

0.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.54
/Pharo/PharoJs-Base-JS-CoreLibraries-Tests/PjDictionaryTest.class.st
1
Class {
2
        #name : 'PjDictionaryTest',
3
        #superclass : 'PjBridgeTestCase',
4
        #category : 'PharoJs-Base-JS-CoreLibraries-Tests-Collections',
5
        #package : 'PharoJs-Base-JS-CoreLibraries-Tests',
6
        #tag : 'Collections'
7
}
8

9
{ #category : 'tests' }
10
PjDictionaryTest >> testAsDictionary [
1✔
11
        | original asDictResult |
1✔
12
        original := self bridge evalBlock: [ Dictionary new].
1✔
13
        original 
1✔
14
                at: #a put: 1;
1✔
15
                at: #b put: 2.
1✔
16
        asDictResult := original asDictionary.
1✔
17
        self assert: original == asDictResult
1✔
18
]
1✔
19

20
{ #category : 'tests' }
21
PjDictionaryTest >> testAtIfAbsent [
1✔
22
        self assertEquivalent: [|d|
1✔
23
                d := Dictionary new.
1✔
24
                d at: #x ifAbsent: [42]].
1✔
25
]
1✔
26

27
{ #category : 'tests' }
28
PjDictionaryTest >> testAtIfAbsentPut [
1✔
29
        self assertEquivalent: [|d|
1✔
30
                d := Dictionary new.
1✔
31
                d at: #x ifAbsentPut: 42.
1✔
32
                d at: #x].
1✔
33
]
1✔
34

35
{ #category : 'tests' }
36
PjDictionaryTest >> testAtIfEmpty [
1✔
37
        self assertEquivalent: [ Dictionary new isEmpty ].
1✔
38
        self assertEquivalent: [ (Dictionary new at: #x put: 4;yourself) isEmpty ].
1✔
39
        self assertEquivalent: [|d|
1✔
40
                d := Dictionary new.
1✔
41
                d ifEmpty: [ 3 ]].
1✔
42
        self assertEquivalent: [|d|
1✔
43
                d := Dictionary new.
1✔
44
                d ifEmpty: [ 3 ] ifNotEmpty: [42]].
1✔
45
        self assertEquivalent: [|d|
1✔
46
                d := Dictionary new.
1✔
47
                d ifNotEmpty: [ 3 ] ifEmpty: [42]].
1✔
48
        self assertEquivalent: [|d t|
1✔
49
                d := Dictionary new.t:=5.
1✔
50
                d at: #x put: 4.
1✔
51
                d ifEmpty: [ t:=3 ].t].
1✔
52
        self assertEquivalent: [|d|
1✔
53
                d := Dictionary new.
1✔
54
                d at: #x put: 4.
1✔
55
                d ifEmpty: [ 3 ] ifNotEmpty: [42]].
1✔
56
        self assertEquivalent: [|d|
1✔
57
                d := Dictionary new.
1✔
58
                d at: #x put: 4.
1✔
59
                d ifNotEmpty: [ 3 ] ifEmpty: [42]].
1✔
60
]
1✔
61

62
{ #category : 'tests' }
UNCOV
63
PjDictionaryTest >> testAtPut [
×
UNCOV
64
        | dict key1 value1 key2 value2 key3 value3 |
×
UNCOV
65
        self assert: [|d|
×
UNCOV
66
                d := Dictionary new.
×
UNCOV
67
                d at: #x put: 42.
×
UNCOV
68
                d] evaluatesToRaw: '{"x":42}'.
×
UNCOV
69
        dict := self evalBlock: [Dictionary new].
×
UNCOV
70
        key1 := self evalBlock: [ 1@1 ].
×
UNCOV
71
        value1 := 'my first point'.
×
UNCOV
72
        key2 := self evalBlock: [ Object ].
×
UNCOV
73
        value2 := 42.
×
UNCOV
74
        key3 := #x.
×
UNCOV
75
        value3 := self evalBlock: [ Object new ].
×
UNCOV
76
        dict at: key1 put: value1.
×
UNCOV
77
        dict at: key2 put: value2.
×
UNCOV
78
        dict at: key3 put: value3.
×
UNCOV
79
        self assert: (dict at: key1) equals: value1.
×
UNCOV
80
        self assert: (dict at: key2) equals: value2.
×
UNCOV
81
        self assert: (dict at: key3) equals: value3
×
UNCOV
82

×
UNCOV
83
]
×
84

85
{ #category : 'tests' }
86
PjDictionaryTest >> testBridgeConstructor [
1✔
87
        | eg |
1✔
88
        eg := self bridge
1✔
89
                evalBlock: [ {(#a -> 3).
1✔
90
                        (#b -> 5)} asDictionary ].
1✔
91
        self assert: [ eg at: #a ] evaluatesTo: 3.
1✔
92
        self assert: [ eg at: #b ] evaluatesTo: 5.
1✔
93
        self
1✔
94
                assert: [ eg
1✔
95
                                add: #c -> 42;
1✔
96
                                at: #c ]
1✔
97
                evaluatesTo: 42.
1✔
98
        self assert: [ eg keys ] evaluatesToRaw: '["a","b","c"]'
1✔
99
]
1✔
100

101
{ #category : 'tests' }
102
PjDictionaryTest >> testBridgeConstructorSimple [
1✔
103
        | eg |
1✔
104
        eg := self bridge evalBlock: [ {(#a -> 3)} asDictionary ].
1✔
105
        self assert: [ eg at: #a ] evaluatesTo: 3.
1✔
106
        self assert: [ eg keys ] evaluatesToRaw: '["a"]'
1✔
107
]
1✔
108

109
{ #category : 'tests' }
110
PjDictionaryTest >> testDictionaryWithProxies [
1✔
111
        | proxy dictionaryWithProxy |
1✔
112
        proxy := self evalBlock: [ Object new ].
1✔
113
        dictionaryWithProxy := { #someId -> proxy } asDictionary.
1✔
114
        self 
1✔
115
                shouldnt: [window instVarNamed: #dict put:  dictionaryWithProxy ]
1✔
116
                raise: Error
1✔
117
]
1✔
118

119
{ #category : 'tests' }
120
PjDictionaryTest >> testKeysAndValuesDo [
1✔
121
        | eg |
1✔
122
        eg := self bridge
1✔
123
                evalBlock: [ {(#a -> 3).
1✔
124
                        (#b -> 5).
1✔
125
                        (#c -> 42)} asDictionary ].
1✔
126
        self
1✔
127
                assert: [ | count |
1✔
128
                        count := 0.
1✔
129
                        eg keysAndValuesDo: [ :k :v | count := count + v ].
1✔
130
                        count ]
1✔
131
                evaluatesTo: 50.
1✔
132
        self
1✔
133
                assert: [ | count |
1✔
134
                        count := 0.
1✔
135
                        eg do: [ :v | count := count + v ].
1✔
136
                        count ]
1✔
137
                evaluatesTo: 50.
1✔
138
        self assert: [ eg isEmpty ] evaluatesTo: false.
1✔
139
        self assert: [ Dictionary new isEmpty ] evaluatesTo: true
1✔
140
]
1✔
141

142
{ #category : 'tests' }
143
PjDictionaryTest >> testNewFromPairs [
1✔
144
        | d |
1✔
145
        d := self bridge
1✔
146
                evalBlock: [ Dictionary newFromPairs: #(#x 17 #y 42) ].
1✔
147
        self assert: d asRawJSONString equals: '{"x":17,"y":42}'
1✔
148
]
1✔
149

150
{ #category : 'tests' }
151
PjDictionaryTest >> testNonInterference [
1✔
152
        " make sure dictionary emulation doesn't interfere "
1✔
153
        self assert: [document body classList add: 'hello'] evaluatesTo: nil.
1✔
154
        self assert: [document body classList contains: 'hello'] evaluatesTo: true
1✔
155
]
1✔
156

157
{ #category : 'tests' }
158
PjDictionaryTest >> testUseEqualObjectsAsKeys [
1✔
159
        self assert: [
1✔
160
                |dict firstKey secondKey| 
1✔
161
                dict := Dictionary new.
1✔
162
                firstKey := PjObjectForDictTest data: 1.
1✔
163
                dict at: firstKey put: 'A'.
1✔
164
                secondKey := PjObjectForDictTest data: 1.
1✔
165
                dict at: secondKey put: 'B'.
1✔
166
                dict at: firstKey
1✔
167
        ] evaluatesTo: 'B'.
1✔
168
]
1✔
169

170
{ #category : 'tests' }
171
PjDictionaryTest >> testUseNonEqualObjectsAsKeys [
1✔
172
        self assert: [
1✔
173
                |dict firstKey secondKey| 
1✔
174
                dict := Dictionary new.
1✔
175
                firstKey := PjObjectForDictTest data: 1.
1✔
176
                dict at: firstKey put: 'A'.
1✔
177
                secondKey := PjObjectForDictTest data: 2.
1✔
178
                dict at: secondKey put: 'B'.
1✔
179
                dict at: firstKey
1✔
180
        ] evaluatesTo: 'A'.
1✔
181
]
1✔
182

183
{ #category : 'tests' }
184
PjDictionaryTest >> testValues [
1✔
185
        | dict  |
1✔
186
        dict := self bridge evalBlock: [ Dictionary new ].
1✔
187
        dict
1✔
188
                at: #a put: 1;
1✔
189
                at: #b put: 2.
1✔
190
        self assertCollection: dict values asLocalObject equals: #(1 2)
1✔
191
]
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc