@@ -46,6 +46,47 @@ describe('fluent.bundle', function ()
4646 assert .equals (" qux" , en :format (" foo.baz" ))
4747 end )
4848
49+ describe (' messages' , function ()
50+ local en = FluentBundle (" en-US" )
51+ en :add_messages (" hi = Hello { $name }!\n foo = bar\n bar = baz\n .bax = qux" )
52+
53+ it (' can be accessed as properties' , function ()
54+ assert .same (" bar" , en .foo :format ())
55+ assert .same (" bar" , en [" foo" ]:format ())
56+ assert .same (" baz" , en .bar :format ())
57+ assert .same (" baz" , en [" bar" ]:format ())
58+ end )
59+
60+ it (' attributes can be accessed as properties' , function ()
61+ assert .same (" qux" , en [" bar.bax" ]())
62+ assert .same (" qux" , en .bar [" bax" ]())
63+ assert .same (" qux" , en .bar .bax ())
64+ end )
65+
66+ it (' can be called' , function ()
67+ assert .same (" bar" , en .foo ())
68+ assert .same (" bar" , en [" foo" ]())
69+ assert .same (" baz" , en .bar ())
70+ assert .same (" baz" , en [" bar" ]())
71+ end )
72+
73+ it (' can be called with parameters' , function ()
74+ assert .same (" Hello World!" , en .hi ({name = " World" }))
75+ assert .same (" Hello World!" , en [" hi" ]({name = " World" }))
76+ assert .same (" Hello World!" , en [" hi" ]:format ({name = " World" }))
77+ end )
78+
79+ it (' can be cast to strings' , function ()
80+ assert .same (" baz" , tostring (en .bar ))
81+ assert .same (" bar" , tostring (en [" foo" ]))
82+ assert .same (" xbar" , " x" .. en .foo )
83+ assert .same (" xbaz" , " x" .. en [" bar" ])
84+ assert .same (" barx" , en .foo .. " x" )
85+ assert .same (" bazx" , en [" bar" ] .. " x" )
86+ end )
87+
88+ end )
89+
4990 it (' should keep locale instances separate' , function ()
5091 local en = FluentBundle (" en-US" )
5192 local tr = FluentBundle (" tr-TR" )
0 commit comments