From 11b596c22dcabf91f9595da778b00e26f4d661a8 Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Thu, 9 Apr 2026 22:04:07 +0800 Subject: bytes,strings: add CutLast Fixes #71151 Change-Id: I3b3d49c35b0fa2c1220d3f39bbd506cc072b52b0 Reviewed-on: https://go-review.googlesource.com/c/go/+/764601 LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com Reviewed-by: David Chase Reviewed-by: Sean Liao Reviewed-by: Robert Griesemer Auto-Submit: Robert Griesemer --- src/strings/strings_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/strings/strings_test.go') diff --git a/src/strings/strings_test.go b/src/strings/strings_test.go index edfeb0e813..4ff3a2a825 100644 --- a/src/strings/strings_test.go +++ b/src/strings/strings_test.go @@ -1826,6 +1826,27 @@ func TestCut(t *testing.T) { } } +func TestCutLast(t *testing.T) { + tests := []struct { + s, sep string + before, after string + found bool + }{ + {"a/b/c", "/", "a/b", "c", true}, + {"a//b//c", "//", "a//b", "c", true}, + {"abc", "/", "abc", "", false}, + {"abc", "", "abc", "", true}, + {"", "", "", "", true}, + {"/abc", "/", "", "abc", true}, + {"abc/", "/", "abc", "", true}, + } + for _, tt := range tests { + if before, after, found := CutLast(tt.s, tt.sep); before != tt.before || after != tt.after || found != tt.found { + t.Errorf("CutLast(%q, %q) = %q, %q, %v; want %q, %q, %v", tt.s, tt.sep, before, after, found, tt.before, tt.after, tt.found) + } + } +} + var cutPrefixTests = []struct { s, sep string after string -- cgit v1.3