@@ -53,22 +53,15 @@ specify std.container:
5353 things = Container {foo="bar", _baz="quux"}
5454 expect (getmetatable (things)).not_to_be (getmetatable (Container))
5555 expect (getmetatable (things)._baz).to_be "quux"
56- - it propagates '_type' and '_module' fields :
56+ - it propagates '_type' field :
5757 things = Container {1}
5858 u, v = things {"u"}, things {"v"}
5959 expect (objtype (u)).to_be "Container"
60- expect (getmetatable (u)._module).to_be "std.container"
6160 expect (objtype (v)).to_be (objtype (Container))
62- expect (getmetatable (v)._module).
63- to_be (getmetatable (Container)._module)
64- - it sets '_type' and '_module' from long prototype '_type' field :
65- things = Container {_type = "specs.example.Things"}
66- expect (objtype (things)).to_be "Things"
67- expect (getmetatable (things)._module).to_be "specs.example"
6861 - context with module functions :
6962 - before :
7063 Bag = require "std.base".object.Module {
71- prototype = Container { _type = "Bag", _module = "specs.example" },
64+ prototype = Container { _type = "Bag" },
7265 count = function (bag)
7366 local n = 0
7467 for _, m in pairs (bag) do n = n + m end
@@ -90,18 +83,11 @@ specify std.container:
9083 - it does allow elements named after module functions :
9184 things = Bag { count = 1337 }
9285 expect (Bag.count (things)).to_be (1337)
93- - it propagates '_type' and '_module' fields :
86+ - it propagates '_type' field :
9487 things = Bag { bananas=0 }
9588 u, v = things { bananas=1 }, things { coconuts=0 }
9689 expect (objtype (u)).to_be "Bag"
97- expect (getmetatable (u)._module).to_be "specs.example"
9890 expect (objtype (v)).to_be (objtype (Bag.prototype))
99- expect (getmetatable (v)._module).
100- to_be (getmetatable (Bag.prototype)._module)
101- - it sets '_type' and '_module' from long prototype '_type' field :
102- things = Bag {_type = "specs.example.Things"}
103- expect (objtype (things)).to_be "Things"
104- expect (getmetatable (things)._module).to_be "specs.example"
10591
10692
10793- describe field access :
@@ -143,50 +129,3 @@ specify std.container:
143129 not_to_contain ";"
144130 expect (tostring (things {one = true, two = true, three = true})).
145131 to_contain ";"
146-
147-
148- - describe __pickle :
149- - before :
150- loadstring = loadstring or load
151- function unpickle (s) return loadstring ("return " .. s) () end
152- f = require "std.string".pickle
153-
154- Derived = Container {_type = "Derived"}
155- things = Derived {one="two", "three"}
156-
157- - it returns a string :
158- expect (type (f (things))).to_be "string"
159- - it resets '_module' metafield when '_type' changes :
160- expect (getmetatable (things)._module).to_be (nil)
161- - it supports setting '_module' and '_type' metafields :
162- Everything = Derived { _type = "Everything", _module = "nearly" }
163- expect (objtype (Everything)).to_be "Everything"
164- expect (getmetatable (Everything)._module).to_be "nearly"
165- Everything = Container { _type = "Everything", _module = "nearly" }
166- expect (objtype (Everything)).to_be "Everything"
167- expect (getmetatable (Everything)._module).to_be "nearly"
168- - it does not have a period in '_type' :
169- Period = Derived { _type = "specs.example.Period" }
170- expect (string.find (type (Period), "%.")).to_be (nil)
171- - it propagates the '_module' metafield when '_type' is unchanged :
172- expect (getmetatable (Container {1})._module).
173- to_be (getmetatable (Container)._module)
174- - context with '_module' metafield :
175- - it requires the module path for later invocation :
176- expect (f (Container)).to_be 'require "std.container".prototype {}'
177- - it roundtrips objects :
178- expect (unpickle (f (Container))).to_equal (Container)
179- - context with '_type' metafield only :
180- - it uses the '_type' value for later invocation :
181- expect (f (things)).to_be 'Derived {[1]="three",["one"]="two"}'
182- - it roundtrips objects :
183- compat = require "specl.compat"
184- compat.setfenv (unpickle, compat.getfenv (1))
185- expect (unpickle (f (things))).to_equal (things)
186- - it converts a nested object to a representative string :
187- container = Container {Derived {"?"}, ["!"]=42}
188- expect (f (container)).
189- to_be 'require "std.container".prototype {[1]=Derived {[1]="?"},["!"]=42}'
190- - it roundtrips nested objects :
191- container = Container {Derived {"?"}, ["!"]=42}
192- expect (unpickle (f (container))).to_equal (container)
0 commit comments