blob: 3108294d09900839a7b245e132cc26c27c5e57d6 [file] [log] [blame]
Logan Chien031d2b32018-07-26 00:19:50 +08001// 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("version numbers in the middle should be ignored", func(t *testing.T) {
39 root, suffix, ext := splitFileExt("libtest.1.0.30.so")
40 expected := "libtest.1.0.30"
41 if root != expected {
42 t.Errorf("root should be %q but got %q", expected, root)
43 }
44 expected = ".so"
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("no known file extension", func(t *testing.T) {
55 root, suffix, ext := splitFileExt("test.exe")
56 expected := "test"
57 if root != expected {
58 t.Errorf("root should be %q but got %q", expected, root)
59 }
60 expected = ".exe"
61 if suffix != expected {
62 t.Errorf("suffix should be %q but got %q", expected, suffix)
63 }
64 if ext != expected {
65 t.Errorf("ext should be %q but got %q", expected, ext)
66 }
67 })
68}