make BString accept String

This commit is contained in:
mykola2312 2024-10-13 22:30:08 +03:00
parent 26901f81af
commit 94617078a4
2 changed files with 10 additions and 0 deletions

View file

@ -10,6 +10,10 @@ public class BString extends BValue {
this.bytes = bytes; this.bytes = bytes;
} }
public BString(String text) {
this.bytes = text.getBytes(StandardCharsets.UTF_8);
}
@Override() @Override()
public boolean compare(BValue other) { public boolean compare(BValue other) {
return Arrays.equals(((BString)other).get(), get()); return Arrays.equals(((BString)other).get(), get());

View file

@ -11,4 +11,10 @@ public class EqualsTest {
assertEquals(new BInteger(1), new BInteger(1)); assertEquals(new BInteger(1), new BInteger(1));
assertNotEquals(new BInteger(2), new BInteger(3)); assertNotEquals(new BInteger(2), new BInteger(3));
} }
@Test
public void testStringEquals() {
assertEquals(new BString("first"), new BString("first"));
assertNotEquals(new BString("first"), new BString("second"));
}
} }