Skip to content

Commit

Permalink
JACOBIN-477 Added unit tests for String class.
Browse files Browse the repository at this point in the history
  • Loading branch information
platypusguy committed Sep 29, 2024
1 parent 4cb9f41 commit 89eb586
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/config/buildno.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

package config

var BuildNo = 3061
var BuildNo = 3062
58 changes: 58 additions & 0 deletions src/gfunction/javaLangString_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,64 @@ func TestStringRegionMatchesWithIgnoreCase(t *testing.T) {
}
}

// test the variants of String.equals()
func TestStringEquals(t *testing.T) {
baseStr := "Hello"
baseStringObject := &object.Object{
KlassName: types.StringPoolStringIndex,
FieldTable: map[string]object.Field{
"value": {Fvalue: []byte(baseStr)},
},
}

compareStr := "Hello"
compareStringObject := &object.Object{
KlassName: types.StringPoolStringIndex,
FieldTable: map[string]object.Field{
"value": {Fvalue: []byte(compareStr)},
},
}

if result := stringEquals([]interface{}{
baseStringObject, compareStringObject}); result != types.JavaBoolTrue {
t.Fatalf("The strings do not match when they should")
}

compareStr = "World"
compareStringObject = &object.Object{
KlassName: types.StringPoolStringIndex,
FieldTable: map[string]object.Field{
"value": {Fvalue: []byte(compareStr)},
},
}

if result := stringEquals([]interface{}{
baseStringObject, compareStringObject}); result != types.JavaBoolFalse {
t.Fatalf("The strings match when they shouldn't")
}

referenceStr := ""
baseStringObject = &object.Object{
KlassName: types.StringPoolStringIndex,
FieldTable: map[string]object.Field{
"value": {Fvalue: []byte(referenceStr)},
},
}

compareToStr := ""
compareStringObject = &object.Object{
KlassName: types.StringPoolStringIndex,
FieldTable: map[string]object.Field{
"value": {Fvalue: []byte(compareToStr)},
},
}

if result := stringEquals([]interface{}{
baseStringObject, compareStringObject}); result != types.JavaBoolTrue {
t.Fatalf("The empty strings do not match when they should")
}
}

// test the variants of index of string
func TestStringIndexOfString(t *testing.T) {
baseStr := "hello world"
Expand Down

0 comments on commit 89eb586

Please sign in to comment.