no bug - Correct some typos in the comments. a=typo-fix
[gecko.git] / third_party / wasm2c / src / test-filenames.cc
blobb734f58bda32b6525c34dd66c0af1811256e0808
1 /*
2 * Copyright 2017 WebAssembly Community Group participants
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "gtest/gtest.h"
19 #include "wabt/filenames.h"
21 using namespace wabt;
23 namespace {
25 void assert_string_view_eq(const char* s, std::string_view sv) {
26 size_t len = std::strlen(s);
27 ASSERT_EQ(len, sv.size());
28 for (size_t i = 0; i < len; ++i) {
29 ASSERT_EQ(s[i], sv[i]);
33 } // end anonymous namespace
35 TEST(filenames, GetBasename) {
36 assert_string_view_eq("foo.txt", GetBasename("/bar/dir/foo.txt"));
37 assert_string_view_eq("foo.txt", GetBasename("bar/dir/foo.txt"));
38 assert_string_view_eq("foo.txt", GetBasename("/foo.txt"));
39 assert_string_view_eq("foo.txt", GetBasename("\\bar\\dir\\foo.txt"));
40 assert_string_view_eq("foo.txt", GetBasename("bar\\dir\\foo.txt"));
41 assert_string_view_eq("foo.txt", GetBasename("\\foo.txt"));
42 assert_string_view_eq("foo.txt", GetBasename("foo.txt"));
43 assert_string_view_eq("foo", GetBasename("foo"));
44 assert_string_view_eq("", GetBasename(""));
47 TEST(filenames, GetExtension) {
48 assert_string_view_eq(".txt", GetExtension("/bar/dir/foo.txt"));
49 assert_string_view_eq(".txt", GetExtension("bar/dir/foo.txt"));
50 assert_string_view_eq(".txt", GetExtension("foo.txt"));
51 assert_string_view_eq("", GetExtension("foo"));
52 assert_string_view_eq("", GetExtension(""));
55 TEST(filenames, StripExtension) {
56 assert_string_view_eq("/bar/dir/foo", StripExtension("/bar/dir/foo.txt"));
57 assert_string_view_eq("bar/dir/foo", StripExtension("bar/dir/foo.txt"));
58 assert_string_view_eq("foo", StripExtension("foo.txt"));
59 assert_string_view_eq("foo", StripExtension("foo"));
60 assert_string_view_eq("", StripExtension(""));