diff options
author | 2019-09-09 20:29:31 -0700 | |
---|---|---|
committer | 2019-09-09 20:29:31 -0700 | |
commit | 022a73b9ad9755230ef876709aff5e21823c4460 (patch) | |
tree | b7b2a5420980397bc02689e5a93d18d500aec387 /android/util_test.go | |
parent | f59007cf23b31a99835eef59065940e8aefb11c7 (diff) |
Move splitFileExt to the android package.
Both Rust and cc use this function, so move it over to android
package's util.go and export it.
Bug: 140734195
Test: m -j
Change-Id: Ibe8b7a94592e402468a027ad6027b187f29c8e07
Diffstat (limited to 'android/util_test.go')
-rw-r--r-- | android/util_test.go | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/android/util_test.go b/android/util_test.go index 2e5eb07ee..1df1c5af5 100644 --- a/android/util_test.go +++ b/android/util_test.go @@ -404,3 +404,68 @@ func ExampleCopyOf_append() { // b = ["foo" "bar"] // c = ["foo" "baz"] } + +func TestSplitFileExt(t *testing.T) { + t.Run("soname with version", func(t *testing.T) { + root, suffix, ext := SplitFileExt("libtest.so.1.0.30") + expected := "libtest" + if root != expected { + t.Errorf("root should be %q but got %q", expected, root) + } + expected = ".so.1.0.30" + if suffix != expected { + t.Errorf("suffix should be %q but got %q", expected, suffix) + } + expected = ".so" + if ext != expected { + t.Errorf("ext should be %q but got %q", expected, ext) + } + }) + + t.Run("soname with svn version", func(t *testing.T) { + root, suffix, ext := SplitFileExt("libtest.so.1svn") + expected := "libtest" + if root != expected { + t.Errorf("root should be %q but got %q", expected, root) + } + expected = ".so.1svn" + if suffix != expected { + t.Errorf("suffix should be %q but got %q", expected, suffix) + } + expected = ".so" + if ext != expected { + t.Errorf("ext should be %q but got %q", expected, ext) + } + }) + + t.Run("version numbers in the middle should be ignored", func(t *testing.T) { + root, suffix, ext := SplitFileExt("libtest.1.0.30.so") + expected := "libtest.1.0.30" + if root != expected { + t.Errorf("root should be %q but got %q", expected, root) + } + expected = ".so" + if suffix != expected { + t.Errorf("suffix should be %q but got %q", expected, suffix) + } + expected = ".so" + if ext != expected { + t.Errorf("ext should be %q but got %q", expected, ext) + } + }) + + t.Run("no known file extension", func(t *testing.T) { + root, suffix, ext := SplitFileExt("test.exe") + expected := "test" + if root != expected { + t.Errorf("root should be %q but got %q", expected, root) + } + expected = ".exe" + if suffix != expected { + t.Errorf("suffix should be %q but got %q", expected, suffix) + } + if ext != expected { + t.Errorf("ext should be %q but got %q", expected, ext) + } + }) +} |