Skip to content

Commit

Permalink
Merge branch 'release/4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ktekinay committed Jan 23, 2019
2 parents fc3180e + be33a4b commit d8501a2
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 105 deletions.
2 changes: 1 addition & 1 deletion JSONItem_MTC Harness/JSONItem_MTC Harness.xojo_project
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Type=Desktop
RBProjectVersion=2018.02
RBProjectVersion=2018.04
MinIDEVersion=20070100
Class=App;App.xojo_code;&h0000000014C611D3;&h0000000000000000;false
MenuBar=MenuBar1;MenuBar1.xojo_menu;&h0000000018745784;&h0000000000000000;false
Expand Down
2 changes: 1 addition & 1 deletion JSONItem_MTC Harness/M_JSON.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ Protected Module M_JSON
#tag Constant, Name = kTab, Type = Double, Dynamic = False, Default = \"9", Scope = Private
#tag EndConstant

#tag Constant, Name = kVersion, Type = Double, Dynamic = False, Default = \"4.0", Scope = Protected
#tag Constant, Name = kVersion, Type = Double, Dynamic = False, Default = \"4.1", Scope = Protected
#tag EndConstant


Expand Down
117 changes: 33 additions & 84 deletions JSONItem_MTC Harness/M_JSON/JSONDictionary.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@
Protected Class JSONDictionary
Inherits Dictionary
#tag Method, Flags = &h0
Function HasKey(key As Variant) As Boolean
if key.Type = Variant.TypeString then
key = EncodeHex( key.StringValue )
end if

Function HasKey(name As Variant) As Boolean
dim key as variant = NameToKey( name )
return super.HasKey( key )
End Function
#tag EndMethod

#tag Method, Flags = &h0
Function Key(index As Integer) As Variant
dim k as variant = super.Key( index )
if k.Type = Variant.TypeString then
k = DecodeHex( k.StringValue )
end if

return k
dim key as variant = super.Key( index )
dim name as string = KeyToName( key )
return name

End Function
#tag EndMethod
Expand All @@ -29,31 +23,42 @@ Inherits Dictionary

for i as integer = 0 to rawKeys.Ubound
dim thisKey as variant = rawKeys( i )
if thisKey.Type = Variant.TypeString then
rawKeys( i ) = DecodeHex( thisKey.StringValue )
end if
rawKeys( i ) = KeyToName( thisKey )
next

return rawKeys
End Function
#tag EndMethod

#tag Method, Flags = &h0
Function Lookup(key As Variant, defaultValue As Variant) As Variant
if key.Type = Variant.TypeString then
key = EncodeHex( key.StringValue )
end if
#tag Method, Flags = &h21
Private Function KeyToName(key As Variant) As String
dim s as string = key.StringValue
dim hex as string = s.NthField( "-", s.CountFields( "-" ) )
dim name as string = s.LeftB( s.LenB - hex.LenB - 1 )
return name

return super.Lookup( key, defaultValue )
End Function
#tag EndMethod

#tag Method, Flags = &h0
Sub Remove(key As Variant)
if key.Type = Variant.TypeString then
key = EncodeHex( key.StringValue )
end if
Function Lookup(name As Variant, defaultValue As Variant) As Variant
dim key as variant = NameToKey( name )
return super.Lookup( key, defaultValue )
End Function
#tag EndMethod

#tag Method, Flags = &h21
Private Function NameToKey(name As String) As Variant
name = name.ConvertEncoding( Encodings.UTF8 )
dim key as variant = name + "-" + EncodeHex( name )
return key

End Function
#tag EndMethod

#tag Method, Flags = &h0
Sub Remove(name As Variant)
dim key as variant = NameToKey( name )
super.Remove( key )

End Sub
Expand All @@ -75,76 +80,20 @@ Inherits Dictionary
#tag EndMethod

#tag Method, Flags = &h0
Function Value(key As Variant) As Variant
if key.Type = Variant.TypeString then
key = EncodeHex( key.StringValue )
end if

Function Value(name As Variant) As Variant
dim key as variant = NameToKey( name )
return super.Value( key )
End Function
#tag EndMethod

#tag Method, Flags = &h0
Sub Value(key As Variant, Assigns v As Variant)
if key.Type = Variant.TypeString then
key = EncodeHex( key.StringValue )
end if

Sub Value(name As Variant, Assigns v As Variant)
dim key as variant = NameToKey( name )
super.Value( key ) = v
End Sub
#tag EndMethod


#tag ComputedProperty, Flags = &h21
#tag Getter
Get
dim rawKeys() as variant = super.Keys
dim rawKeysString() as string

//
// Remove the non-strings and get some stats
//
dim longest as integer
dim shortest as integer = &h7FFFFFFF

for i as integer = 0 to rawKeys.Ubound
dim thisKey as variant = rawKeys( i )

if thisKey.Type = Variant.TypeString then
rawKeysString.Append thisKey.StringValue

dim thisLen as integer = thisKey.StringValue.LenB
longest = max( longest, thisLen )
shortest = min( shortest, thisLen )
end if
next

rawKeysString.Sort

dim padder as string = " "
while padder.LenB < longest
padder = padder + padder
wend

dim builder() as string

for i as integer = 0 to rawKeysString.Ubound
dim thisKey as string = rawKeysString( i )

dim row as string = padder + thisKey + " = "
row = row.Right( longest + 3 )
row = row + DecodeHex( thisKey )
builder.Append row
next

dim r as string = join( builder, EndOfLine )
return r
End Get
#tag EndGetter
Private DebugKeyMap As String
#tag EndComputedProperty


#tag ViewBehavior
#tag ViewProperty
Name="BinCount"
Expand Down
45 changes: 41 additions & 4 deletions JSONItem_MTC Harness/Tests/BasicTests_JSONItem.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,40 @@ Inherits TestGroup
#tag Method, Flags = &h21
Private Sub CaseSensitiveKeyTest()
dim j as new JSONItem
j.Value( "a" ) = 1
j.Value( "A" ) = 2

Assert.AreEqual( 2, j.Count, "Should be 2 objects" )
dim storedKeys() as string = array( _
"a", _
"A", _
"a" + &u200B + "A", _
"A" + &u200B + "A", _
"a" + &u200B + "a" _
)

for i as integer = 0 to storedKeys.Ubound
dim key as string = storedKeys( i )
j.Value( key ) = i + 1
next

Assert.AreEqual( CType( storedKeys.Ubound, integer ) + 1, j.Count, "Should be 5 objects" )
Assert.AreEqual( 1, j.Value( "a" ).IntegerValue )

j.Value( "Man" ) = 3
dim keys() as string = j.Names

for each storedKey as string in storedKeys
dim startingUb as integer = keys.Ubound
for i as integer = keys.Ubound downto 0
if StrComp( keys( i ), storedKey, 0 ) = 0 then
keys.Remove i
exit for i
end if
next
dim endingUb as integer = keys.Ubound
Assert.AreEqual( startingUb - 1, endingUb, storedKey.ToText + " was not found" )
next

Assert.AreEqual( -1, CType( keys.Ubound, integer ), "keys should be empty" )

j.Value( "Man" ) = 6
Assert.IsFalse( j.HasName( "MaT" ), "Keys with same Base64 encoding return incorrect results" )

End Sub
Expand Down Expand Up @@ -206,6 +233,16 @@ Inherits TestGroup


#tag ViewBehavior
#tag ViewProperty
Name="IsRunning"
Group="Behavior"
Type="Boolean"
#tag EndViewProperty
#tag ViewProperty
Name="StopTestOnFail"
Group="Behavior"
Type="Boolean"
#tag EndViewProperty
#tag ViewProperty
Name="Duration"
Group="Behavior"
Expand Down
46 changes: 42 additions & 4 deletions JSONItem_MTC Harness/Tests/BasicTests_JSONItem_MTC.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,43 @@ Inherits TestGroup
#tag Method, Flags = &h21
Private Sub CaseSensitiveKeyTest()
dim j as new JSONItem_MTC
j.Value( "a" ) = 1
j.Value( "A" ) = 2

Assert.AreEqual( 2, j.Count, "Should be 2 objects" )
dim storedKeys() as string = array( _
"a", _
"A", _
"a" + &u200B + "A", _
"A" + &u200B + "A", _
"a" + &u200B + "a" _
)

for i as integer = 0 to storedKeys.Ubound
dim key as string = storedKeys( i )
j.Value( key ) = i + 1
next

Assert.AreEqual( CType( storedKeys.Ubound, integer ) + 1, j.Count, "Should be 5 objects" )
Assert.AreEqual( 1, j.Value( "a" ).IntegerValue )

j.Value( "Man" ) = 3
dim keys() as string = j.Names

for each storedKey as string in storedKeys
dim startingUb as integer = keys.Ubound
for i as integer = keys.Ubound downto 0
if StrComp( keys( i ), storedKey, 0 ) = 0 then
keys.Remove i
exit for i
end if
next
dim endingUb as integer = keys.Ubound
Assert.AreEqual( startingUb - 1, endingUb, storedKey.ToText + " was not found" )
next

Assert.AreEqual( -1, CType( keys.Ubound, integer ), "keys should be empty" )

j.Value( "Man" ) = 6
Assert.IsFalse( j.HasName( "MaT" ), "Keys with same Base64 encoding return incorrect results" )


End Sub
#tag EndMethod

Expand Down Expand Up @@ -615,6 +643,16 @@ Inherits TestGroup


#tag ViewBehavior
#tag ViewProperty
Name="IsRunning"
Group="Behavior"
Type="Boolean"
#tag EndViewProperty
#tag ViewProperty
Name="StopTestOnFail"
Group="Behavior"
Type="Boolean"
#tag EndViewProperty
#tag ViewProperty
Name="Duration"
Group="Behavior"
Expand Down
28 changes: 28 additions & 0 deletions JSONItem_MTC Harness/Tests/M_JSONTests.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ Inherits TestGroup
End Sub
#tag EndMethod

#tag Method, Flags = &h0
Sub CaseSensitiveNamesTest()
dim s as string = "{""Abc"":1, ""ABC"":2, ""abc"":3}"

dim d as Dictionary = ParseJSON_MTC( s )
Assert.IsTrue( Introspection.GetType( d ) = GetTypeInfo( M_JSON.JSONDictionary ), "Is not JSONDictionary" )

Assert.AreEqual( 3, d.Count, "Dictionary.Count does not match" )
Assert.AreEqual( 1, d.Value( "Abc" ).IntegerValue, "Abc" )
Assert.AreEqual( 2, d.Value( "ABC" ).IntegerValue, "ABC" )
Assert.AreEqual( 3, d.Value( "abc" ).IntegerValue, "abc" )


End Sub
#tag EndMethod

#tag Method, Flags = &h0
Sub DifferentEncodingsTest()
dim json as string = "[1,2,""©""]"
Expand Down Expand Up @@ -283,6 +299,18 @@ Inherits TestGroup
End Sub
#tag EndMethod

#tag Method, Flags = &h0
Sub JSONDictionaryTextKeyTest()
dim t as text = "someTextKey"
dim s as string = t

dim d as new M_JSON.JSONDictionary

d.Value( t ) = 1
Assert.AreEqual( 1, d.Value( s ).IntegerValue, "Text key does not match" )
End Sub
#tag EndMethod

#tag Method, Flags = &h0
Sub JSONDIctionaryToDictionaryTest()
dim jd as M_JSON.JSONDictionary = ParseJSON_MTC( "{""aa"" : 1, ""AA"" : 2, ""Aa"" : 3}" )
Expand Down
Loading

0 comments on commit d8501a2

Please sign in to comment.