generated from platypusguy/jacobin-swift
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JACOBIN-583 Corrected misspelling in name of file, removed block of c…
…ommented out tests
- Loading branch information
1 parent
fb6000d
commit 1626cb4
Showing
2 changed files
with
96 additions
and
421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Jacobin VM - A Java virtual machine | ||
* Copyright (c) 2024-5 by the Jacobin Authors. All rights reserved. | ||
* Licensed under Mozilla Public License 2.0 (MPL 2.0) Consult jacobin.org. | ||
*/ | ||
|
||
package gfunction | ||
|
||
import ( | ||
"jacobin/excNames" | ||
"jacobin/object" | ||
"jacobin/types" | ||
"testing" | ||
) | ||
|
||
func TestStringBuilderInit(t *testing.T) { | ||
// Test case: without capacity | ||
params := []any{object.MakeEmptyObject()} | ||
result := stringBuilderInit(params) | ||
if result != nil { | ||
t.Errorf("Expected nil, got %v", result) | ||
} | ||
|
||
// Test case: with capacity | ||
obj := object.MakeEmptyObject() | ||
params = []any{obj, int64(32)} | ||
result = stringBuilderInit(params) | ||
if result != nil { | ||
t.Errorf("Expected nil, got %v", result) | ||
} | ||
|
||
if obj.FieldTable["capacity"].Fvalue != int64(32) { | ||
t.Errorf("Expected 32, got %v", result.(*object.Object).FieldTable["capacity"].Fvalue) | ||
} | ||
} | ||
|
||
func TestStringBuilderInitString(t *testing.T) { | ||
// Test case: valid string object | ||
obj := object.MakeEmptyObject() | ||
strObj := object.StringObjectFromGoString("Hello") | ||
params := []any{obj, strObj} | ||
result := stringBuilderInitString(params) | ||
if result != nil { | ||
t.Errorf("Expected nil, got %v", result) | ||
} | ||
|
||
if object.GoStringFromJavaByteArray(obj.FieldTable["value"].Fvalue.([]types.JavaByte)) != | ||
object.GoStringFromJavaByteArray(strObj.FieldTable["value"].Fvalue.([]types.JavaByte)) { | ||
t.Errorf("Expected %v, got %v", strObj.FieldTable["value"].Fvalue, | ||
result.(*object.Object).FieldTable["value"].Fvalue) | ||
} | ||
|
||
// Test case: invalid parameter type | ||
params = []any{obj, 123} | ||
result = stringBuilderInitString(params) | ||
if result == nil || result.(*GErrBlk).ExceptionType != excNames.IllegalArgumentException { | ||
t.Errorf("Expected IllegalArgumentException, got %s", | ||
excNames.JVMexceptionNames[result.(*GErrBlk).ExceptionType]) | ||
} | ||
} | ||
|
||
func TestStringBuilderToString(t *testing.T) { | ||
// Test case: convert to string | ||
obj := object.NewStringObject() | ||
obj.FieldTable["value"] = object.Field{Ftype: types.ByteArray, Fvalue: []types.JavaByte{'H', 'e', 'l', 'l', 'o'}} | ||
params := []any{obj} | ||
result := stringBuilderToString(params) | ||
if result == nil { | ||
t.Errorf("Expected non-nil result, got nil") | ||
} | ||
if result == "Hello" { | ||
t.Errorf("Expected 'Hello', got %s", result) | ||
} | ||
} | ||
|
||
func TestStringBuilderCapacity(t *testing.T) { | ||
// Test case: get capacity | ||
obj := object.MakeEmptyObject() | ||
obj.FieldTable["capacity"] = object.Field{Ftype: types.Int, Fvalue: int64(16)} | ||
params := []any{obj} | ||
result := stringBuilderCapacity(params) | ||
if result != int64(16) { | ||
t.Errorf("Expected 16, got %v", result) | ||
} | ||
} | ||
|
||
func TestStringBuilderLength(t *testing.T) { | ||
// Test case: get length | ||
obj := object.MakeEmptyObject() | ||
obj.FieldTable["count"] = object.Field{Ftype: types.Int, Fvalue: int64(5)} | ||
params := []any{obj} | ||
result := stringBuilderLength(params) | ||
if result != int64(5) { | ||
t.Errorf("Expected 5, got %v", result) | ||
} | ||
} |
Oops, something went wrong.