From f5eb0744d542ca21b9fb5d5bc85827f30a73adca Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Fri, 29 Aug 2025 21:30:55 +0200 Subject: [PATCH] Added strings.equal --- lib/strings/strings.q | 17 +++++++++++++++++ tests/string-equal.q | 8 ++++++++ tests/tests_test.go | 1 + 3 files changed, 26 insertions(+) create mode 100644 lib/strings/strings.q create mode 100644 tests/string-equal.q 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}, -- 2.54.0