Mercurial > hg > CbC > CbC_llvm
comparison unittests/ADT/StringSwitchTest.cpp @ 147:c2174574ed3a
LLVM 10
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 16:55:33 +0900 |
parents | 1172e4bd9c6f |
children |
comparison
equal
deleted
inserted
replaced
134:3a76565eade5 | 147:c2174574ed3a |
---|---|
1 //===- llvm/unittest/ADT/StringSwitchTest.cpp - StringSwitch unit tests ---===// | 1 //===- llvm/unittest/ADT/StringSwitchTest.cpp - StringSwitch unit tests ---===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 // | 4 // See https://llvm.org/LICENSE.txt for license information. |
5 // This file is distributed under the University of Illinois Open Source | 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 // License. See LICENSE.TXT for details. | |
7 // | 6 // |
8 //===----------------------------------------------------------------------===// | 7 //===----------------------------------------------------------------------===// |
9 | 8 |
10 #include "llvm/ADT/StringSwitch.h" | 9 #include "llvm/ADT/StringSwitch.h" |
11 #include "gtest/gtest.h" | 10 #include "gtest/gtest.h" |
156 TEST(StringSwitchTest, Cases) { | 155 TEST(StringSwitchTest, Cases) { |
157 enum class OSType { Windows, Linux, Unknown }; | 156 enum class OSType { Windows, Linux, Unknown }; |
158 | 157 |
159 auto Translate = [](StringRef S) { | 158 auto Translate = [](StringRef S) { |
160 return llvm::StringSwitch<OSType>(S) | 159 return llvm::StringSwitch<OSType>(S) |
161 .Cases("wind\0ws", "win32", "winnt", OSType::Windows) | 160 .Cases(StringLiteral::withInnerNUL("wind\0ws"), "win32", "winnt", |
161 OSType::Windows) | |
162 .Cases("linux", "unix", "*nix", "posix", OSType::Linux) | 162 .Cases("linux", "unix", "*nix", "posix", OSType::Linux) |
163 .Default(OSType::Unknown); | 163 .Default(OSType::Unknown); |
164 }; | 164 }; |
165 | 165 |
166 EXPECT_EQ(OSType::Windows, Translate(llvm::StringRef("wind\0ws", 7))); | 166 EXPECT_EQ(OSType::Windows, Translate(llvm::StringRef("wind\0ws", 7))); |
182 TEST(StringSwitchTest, CasesLower) { | 182 TEST(StringSwitchTest, CasesLower) { |
183 enum class OSType { Windows, Linux, Unknown }; | 183 enum class OSType { Windows, Linux, Unknown }; |
184 | 184 |
185 auto Translate = [](StringRef S) { | 185 auto Translate = [](StringRef S) { |
186 return llvm::StringSwitch<OSType>(S) | 186 return llvm::StringSwitch<OSType>(S) |
187 .CasesLower("wind\0ws", "win32", "winnt", OSType::Windows) | 187 .CasesLower(StringLiteral::withInnerNUL("wind\0ws"), "win32", "winnt", |
188 OSType::Windows) | |
188 .CasesLower("linux", "unix", "*nix", "posix", OSType::Linux) | 189 .CasesLower("linux", "unix", "*nix", "posix", OSType::Linux) |
189 .Default(OSType::Unknown); | 190 .Default(OSType::Unknown); |
190 }; | 191 }; |
191 | 192 |
192 EXPECT_EQ(OSType::Windows, Translate(llvm::StringRef("WIND\0WS", 7))); | 193 EXPECT_EQ(OSType::Windows, Translate(llvm::StringRef("WIND\0WS", 7))); |