StringExtrasTest.cpp
2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//===- StringExtrasTest.cpp - Tests for utility methods in StringExtras.h -===//
//
// Part of the MLIR Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "mlir/Support/StringExtras.h"
#include "gtest/gtest.h"
using namespace mlir;
static void testConvertToSnakeCase(llvm::StringRef input,
llvm::StringRef expected) {
EXPECT_EQ(convertToSnakeCase(input), expected.str());
}
TEST(StringExtras, ConvertToSnakeCase) {
testConvertToSnakeCase("OpName", "op_name");
testConvertToSnakeCase("opName", "op_name");
testConvertToSnakeCase("_OpName", "_op_name");
testConvertToSnakeCase("Op_Name", "op_name");
testConvertToSnakeCase("", "");
testConvertToSnakeCase("A", "a");
testConvertToSnakeCase("_", "_");
testConvertToSnakeCase("a", "a");
testConvertToSnakeCase("op_name", "op_name");
testConvertToSnakeCase("_op_name", "_op_name");
testConvertToSnakeCase("__op_name", "__op_name");
testConvertToSnakeCase("op__name", "op__name");
}
template <bool capitalizeFirst>
static void testConvertToCamelCase(llvm::StringRef input,
llvm::StringRef expected) {
EXPECT_EQ(convertToCamelCase(input, capitalizeFirst), expected.str());
}
TEST(StringExtras, ConvertToCamelCase) {
testConvertToCamelCase<false>("op_name", "opName");
testConvertToCamelCase<false>("_op_name", "_opName");
testConvertToCamelCase<false>("__op_name", "_OpName");
testConvertToCamelCase<false>("op__name", "op_Name");
testConvertToCamelCase<false>("", "");
testConvertToCamelCase<false>("A", "A");
testConvertToCamelCase<false>("_", "_");
testConvertToCamelCase<false>("a", "a");
testConvertToCamelCase<false>("OpName", "OpName");
testConvertToCamelCase<false>("opName", "opName");
testConvertToCamelCase<false>("_OpName", "_OpName");
testConvertToCamelCase<false>("Op_Name", "Op_Name");
testConvertToCamelCase<true>("op_name", "OpName");
testConvertToCamelCase<true>("_op_name", "_opName");
testConvertToCamelCase<true>("__op_name", "_OpName");
testConvertToCamelCase<true>("op__name", "Op_Name");
testConvertToCamelCase<true>("", "");
testConvertToCamelCase<true>("A", "A");
testConvertToCamelCase<true>("_", "_");
testConvertToCamelCase<true>("a", "A");
testConvertToCamelCase<true>("OpName", "OpName");
testConvertToCamelCase<true>("_OpName", "_OpName");
testConvertToCamelCase<true>("Op_Name", "Op_Name");
testConvertToCamelCase<true>("opName", "OpName");
}