diff --git a/lib/strings/strings.q b/lib/strings/strings.q new file mode 100644 index 0000000..ffd2d41 --- /dev/null +++ b/lib/strings/strings.q @@ -0,0 +1,17 @@ +equal(a string, b string) -> bool { + if a.len != b.len { + return false + } + + if a.ptr == b.ptr { + return true + } + + loop i := 0..a.len { + if a[i] != b[i] { + return false + } + } + + return true +} \ No newline at end of file diff --git a/tests/string-equal.q b/tests/string-equal.q new file mode 100644 index 0000000..ca1fecf --- /dev/null +++ b/tests/string-equal.q @@ -0,0 +1,8 @@ +import strings + +main() { + assert strings.equal("world", "universe") == false + assert strings.equal("world", "world") == true + assert strings.equal("世界", "宇宙") == false + assert strings.equal("世界", "世界") == true +} \ No newline at end of file diff --git a/tests/tests_test.go b/tests/tests_test.go index 53ee956..add5e80 100644 --- a/tests/tests_test.go +++ b/tests/tests_test.go @@ -80,6 +80,7 @@ var tests = []run{ {"return-string", "", "Hello\n", 0}, {"ignore-unused-field", "", "", 0}, {"slice", "", "Hello World", 0}, + {"string-equal", "", "", 0}, {"reorder-add", "", "", 0}, {"free-registers", "", "", 0}, {"overload", "", "", 0},