1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <string>
11
12 // template<> struct char_traits<char>
13
14 // static int compare(const char_type* s1, const char_type* s2, size_t n);
15
16 #include <string>
17 #include <cassert>
18
main()19 int main()
20 {
21 assert(std::char_traits<char>::compare("", "", 0) == 0);
22 assert(std::char_traits<char>::compare(NULL, NULL, 0) == 0);
23
24 assert(std::char_traits<char>::compare("1", "1", 1) == 0);
25 assert(std::char_traits<char>::compare("1", "2", 1) < 0);
26 assert(std::char_traits<char>::compare("2", "1", 1) > 0);
27
28 assert(std::char_traits<char>::compare("12", "12", 2) == 0);
29 assert(std::char_traits<char>::compare("12", "13", 2) < 0);
30 assert(std::char_traits<char>::compare("12", "22", 2) < 0);
31 assert(std::char_traits<char>::compare("13", "12", 2) > 0);
32 assert(std::char_traits<char>::compare("22", "12", 2) > 0);
33
34 assert(std::char_traits<char>::compare("123", "123", 3) == 0);
35 assert(std::char_traits<char>::compare("123", "223", 3) < 0);
36 assert(std::char_traits<char>::compare("123", "133", 3) < 0);
37 assert(std::char_traits<char>::compare("123", "124", 3) < 0);
38 assert(std::char_traits<char>::compare("223", "123", 3) > 0);
39 assert(std::char_traits<char>::compare("133", "123", 3) > 0);
40 assert(std::char_traits<char>::compare("124", "123", 3) > 0);
41 }
42