• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
18	"testing"
19)
20
21func TestSplitFileExt(t *testing.T) {
22	t.Run("soname with version", func(t *testing.T) {
23		root, suffix, ext := splitFileExt("libtest.so.1.0.30")
24		expected := "libtest"
25		if root != expected {
26			t.Errorf("root should be %q but got %q", expected, root)
27		}
28		expected = ".so.1.0.30"
29		if suffix != expected {
30			t.Errorf("suffix should be %q but got %q", expected, suffix)
31		}
32		expected = ".so"
33		if ext != expected {
34			t.Errorf("ext should be %q but got %q", expected, ext)
35		}
36	})
37
38	t.Run("soname with svn version", func(t *testing.T) {
39		root, suffix, ext := splitFileExt("libtest.so.1svn")
40		expected := "libtest"
41		if root != expected {
42			t.Errorf("root should be %q but got %q", expected, root)
43		}
44		expected = ".so.1svn"
45		if suffix != expected {
46			t.Errorf("suffix should be %q but got %q", expected, suffix)
47		}
48		expected = ".so"
49		if ext != expected {
50			t.Errorf("ext should be %q but got %q", expected, ext)
51		}
52	})
53
54	t.Run("version numbers in the middle should be ignored", func(t *testing.T) {
55		root, suffix, ext := splitFileExt("libtest.1.0.30.so")
56		expected := "libtest.1.0.30"
57		if root != expected {
58			t.Errorf("root should be %q but got %q", expected, root)
59		}
60		expected = ".so"
61		if suffix != expected {
62			t.Errorf("suffix should be %q but got %q", expected, suffix)
63		}
64		expected = ".so"
65		if ext != expected {
66			t.Errorf("ext should be %q but got %q", expected, ext)
67		}
68	})
69
70	t.Run("no known file extension", func(t *testing.T) {
71		root, suffix, ext := splitFileExt("test.exe")
72		expected := "test"
73		if root != expected {
74			t.Errorf("root should be %q but got %q", expected, root)
75		}
76		expected = ".exe"
77		if suffix != expected {
78			t.Errorf("suffix should be %q but got %q", expected, suffix)
79		}
80		if ext != expected {
81			t.Errorf("ext should be %q but got %q", expected, ext)
82		}
83	})
84}
85