@@ -752,3 +752,102 @@ async def test_term_api(api):
752752 await term_step (api , 'You must have seen different shades of red made using palettes' )
753753
754754 await api .print ('Test finished successfully' )
755+
756+
757+ async def test_settings_api (api ):
758+ tbl = await get_object_table (api , 'settings' )
759+ assert get_class_table (api .settings .__class__ ) == tbl
760+
761+ await step (api , 'Settings will be cleared' )
762+
763+ assert await api .settings .clear () is None
764+ # names are not empty, there are system settings
765+ assert isinstance (await api .settings .getNames (), list )
766+
767+ assert await api .settings .define ('test.a' ) is None
768+ assert await api .settings .define ('test.b' , description = 'b' ) is None
769+ assert await api .settings .define ('test.c' , type = 'string' ) is None
770+ assert await api .settings .define ('test.d' , default = 42 ) is None
771+
772+ assert await api .settings .getDetails ('test.a' ) == {
773+ 'changed' : False ,
774+ }
775+ assert await api .settings .getDetails ('test.b' ) == {
776+ 'changed' : False ,
777+ 'description' : 'b' ,
778+ }
779+ assert await api .settings .getDetails ('test.c' ) == {
780+ 'changed' : False ,
781+ 'type' : 'string' ,
782+ }
783+ assert await api .settings .getDetails ('test.d' ) == {
784+ 'changed' : False ,
785+ 'default' : 42 ,
786+ 'value' : 42 ,
787+ }
788+
789+ # redefining
790+ assert await api .settings .define ('test.a' , type = 'number' , default = 11 ) is None
791+
792+ assert await api .settings .getDetails ('test.a' ) == {
793+ 'changed' : False ,
794+ 'type' : 'number' ,
795+ 'default' : 11 ,
796+ 'value' : 11 ,
797+ }
798+
799+ assert await api .settings .get ('test.a' ) == 11
800+ assert await api .settings .set ('test.a' , 12 ) is None
801+ assert await api .settings .get ('test.a' ) == 12
802+ with assert_raises (LuaException ):
803+ await api .settings .set ('test.a' , 'text' )
804+ assert await api .settings .get ('test.a' ) == 12
805+ assert await api .settings .unset ('test.a' ) is None
806+ assert await api .settings .get ('test.a' ) == 11
807+
808+ assert await api .settings .set ('test.c' , 'hello' ) is None
809+
810+ assert {'test.a' , 'test.b' , 'test.c' , 'test.d' }.issubset (set (await api .settings .getNames ()))
811+
812+ assert await api .settings .undefine ('test.a' ) is None
813+ assert await api .settings .undefine ('test.b' ) is None
814+ assert await api .settings .undefine ('test.c' ) is None
815+ assert await api .settings .undefine ('test.d' ) is None
816+
817+ assert 'test.c' in await api .settings .getNames ()
818+ assert await api .settings .get ('test.c' ) == 'hello'
819+ assert await api .settings .getDetails ('test.c' ) == {
820+ 'changed' : True ,
821+ 'value' : 'hello' ,
822+ }
823+
824+ assert await api .settings .unset ('test.c' ) is None
825+
826+ assert await api .settings .get ('test.c' ) is None
827+ assert await api .settings .getDetails ('test.c' ) == {
828+ 'changed' : False ,
829+ }
830+
831+ assert {'test.a' , 'test.b' , 'test.c' , 'test.d' } & set (await api .settings .getNames ()) == set ()
832+
833+ assert await api .settings .set ('test.e' , [9 , 'text' , False ]) is None
834+ assert await api .settings .get ('test.e' ) == [9 , 'text' , False ]
835+ assert await api .settings .clear () is None
836+ assert await api .settings .get ('test.e' ) is None
837+
838+ await api .fs .delete ('.settings' )
839+
840+ assert await api .settings .load () is False
841+ assert await api .settings .save () is True
842+ assert await api .settings .load () is True
843+
844+ await api .fs .delete ('.settings' )
845+
846+ assert await api .settings .set ('key' , 84 ) is None
847+
848+ assert await api .settings .save ('sfile' ) is True
849+ assert await api .settings .load ('sfile' ) is True
850+
851+ await api .fs .delete ('sfile' )
852+
853+ await api .print ('Test finished successfully' )
0 commit comments