72 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8// UNSUPPORTED: c++03, c++11, c++14, c++179 10// <string>11 12// constexpr bool starts_with(const CharT *x) const;13 14#include <string>15#include <cassert>16 17#include "test_macros.h"18 19template <class S>20constexpr void test_string() {21 const char* s = "abcde";22 S s0{};23 S s1{s, 1};24 S s2{s, 2};25 // S s3 { s, 3 };26 // S s4 { s, 4 };27 // S s5 { s, 5 };28 S sNot{"def", 3};29 30 LIBCPP_ASSERT_NOEXCEPT(s0.starts_with(""));31 32 assert(s0.starts_with(""));33 assert(!s0.starts_with("a"));34 35 assert(s1.starts_with(""));36 assert(s1.starts_with("a"));37 assert(!s1.starts_with("ab"));38 assert(!s1.starts_with("abc"));39 assert(!s1.starts_with("abcd"));40 assert(!s1.starts_with("abcde"));41 assert(!s1.starts_with("def"));42 43 assert(s2.starts_with(""));44 assert(s2.starts_with("a"));45 assert(s2.starts_with("ab"));46 assert(!s2.starts_with("abc"));47 assert(!s2.starts_with("abcd"));48 assert(!s2.starts_with("abcde"));49 assert(!s2.starts_with("def"));50 51 assert(sNot.starts_with(""));52 assert(!sNot.starts_with("a"));53 assert(!sNot.starts_with("ab"));54 assert(!sNot.starts_with("abc"));55 assert(!sNot.starts_with("abcd"));56 assert(!sNot.starts_with("abcde"));57 assert(sNot.starts_with("def"));58}59 60constexpr bool test() {61 test_string<std::string>();62 63 return true;64}65 66int main(int, char**) {67 test();68 static_assert(test());69 70 return 0;71}72