Skip to content

Commit

Permalink
v1.1
Browse files Browse the repository at this point in the history
- enum type added by Deathfly
- added test related to bug
- fixed parsing numbers with a leading decimal point (i.e., ".8")
  • Loading branch information
Trylobot committed Jul 9, 2017
1 parent 89b7cd9 commit fc0602a
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 63 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

*.exe
mod/twrc.mod/rjson.mod/rjson.bmx
*.s
*.o
2 changes: 0 additions & 2 deletions bmx-rjson.url

This file was deleted.

3 changes: 2 additions & 1 deletion build.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bmk makemods twrc.rjson
set "BMK_LD_OPTS=-lmsvcrt -lgcc"
bmk makemods -a twrc.rjson
pause
1 change: 1 addition & 0 deletions build_test.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
set "BMK_LD_OPTS=-lmsvcrt -lgcc"
bmk makeapp -d rjson-test.bmx
pause

1 change: 1 addition & 0 deletions do_all.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ CALL build
CALL build_test

CALL run_test

38 changes: 35 additions & 3 deletions rjson-test.bmx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ Function test_number_literal()
verify( val.Equals( json.parse( json_str )) )
EndFunction

Function test_number_literal2()
Print "*** test_number_literal with trailing f"
Local json_str$ = "1234.0f"
Local val:TNumber = New TNumber; val.value = 1234;
verify( val.Equals( json.parse( json_str )) )
EndFunction

Function test_number_literal3()
Print "*** test_number_literal starting with decimal point"
Local json_str$ = ".8"
Local test_val:TNumber = New TNumber
test_val.value = 0.8;
Local decoded_val:TNumber = TNumber( json.parse( json_str ))
Local test_val_str$ = json.FormatDouble( test_val.value )
Local decoded_val_str$ = json.FormatDouble( decoded_val.value )
verify( test_val_str = decoded_val_str, ""+test_val_str+" <> "+decoded_val_str )
EndFunction

Function test_null_literal()
Print "*** test_null_literal"
Local json_str$ = "null"
Expand Down Expand Up @@ -532,7 +550,9 @@ Function test_pass_starfarer()
Print "*** test_pass_starfarer"
Local json_str$ = LoadString( test_dir + "/passes/starfarer.json" )
Local decoded:Object = json.parse( json_str )
verify( TObject(decoded).fields.ValueForKey( "enum1" ).ToString() = "~qENUM_VALUE~q", "~qENUM_VALUE~q <> "+TObject(decoded).fields.ValueForKey( "enum1" ).ToString() )
verify( ..
TObject(decoded).fields.ValueForKey( "enum1" ).ToString() = "ENUM_VALUE", ..
"ENUM_VALUE <> "+TObject(decoded).fields.ValueForKey( "enum1" ).ToString() )
EndFunction

Function test_encode_TList()
Expand Down Expand Up @@ -569,8 +589,8 @@ Function test_tvalue_transformation_search()
verify( json_out_expected = json_out_actual, " EXPECTED:~n"+json_out_expected+"~n ACTUAL:~n"+json_out_actual )
EndFunction


Function test_tvalue_transformation_conditional_delete()
rem
Print "*** test_tvalue_transformation_conditional_delete"
Local json_str$ = LoadString( test_dir + "/passes/xf2_in.json" )
json.add_transform( "parse", ":object/$ALPHA:string", json.XJ_DELETE )
Expand All @@ -580,13 +600,13 @@ Function test_tvalue_transformation_conditional_delete()
Local val:TValue = TValue( json.parse( json_str,, "parse" ))
verify( TObject(TArray( val ).elements.ValueAtIndex(8)).fields.Contains("ALPHA") = False, "value should not be found" )
json.clear_transforms()
endrem
EndFunction
Function __TBoolean_NOT%( val:TValue )
If TBoolean(val) Then Return (Not TBoolean(val).value) ..
Else Return False
EndFunction


Function test_pass_sf_1()
Print "*** test_pass_sf_1"
Local json_str$ = LoadString( test_dir + "/passes/sfw1.json" )
Expand Down Expand Up @@ -621,6 +641,15 @@ Function test_encode_empty_objects_instead_of_nulls()
verify( test_str = json_str, " EXPECTED:~n"+test_str+"~n ACTUAL:~n"+json_str )
EndFunction

Function bug1()
'Print "*** reported bug 1"
'Local json_str$ = LoadString( test_dir + "/passes/bug1.json" )
'Local val:Object = json.parse( json_str )
'Local check:TNumber = TNumber(TObject(TObject(val).Get("exigencyEngine")).Get("contrailMaxSpeedMult"))
'Local expected:Double = 0.1:Double
'verify( expected = check.value, " EXPECTED: "+expected+" ACTUAL: "+check.value )
EndFunction


'/////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -657,6 +686,8 @@ Function Main()
run_test( test_string_with_line_break )
run_test( test_string_literal )
run_test( test_number_literal )
run_test( test_number_literal2 )
run_test( test_number_literal3 )
run_test( test_null_literal )
run_test( test_boolean_literal )
run_test( test_unclosed_array )
Expand Down Expand Up @@ -704,6 +735,7 @@ Function Main()
run_test( test_pass_sf_1 )
run_test( test_pass_sf_2 )
run_test( test_encode_empty_objects_instead_of_nulls )
run_test( bug1 )
EndFunction

Main()
Expand Down
Loading

0 comments on commit fc0602a

Please sign in to comment.