summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/experimental/string_view/operations/compare
diff options
context:
space:
mode:
authoremsr <emsr@138bc75d-0d04-0410-961f-82ee72b054a4>2013-11-16 17:44:48 +0000
committeremsr <emsr@138bc75d-0d04-0410-961f-82ee72b054a4>2013-11-16 17:44:48 +0000
commit2fd2d470862f7a6aa1dbb6184ed1863202d59e0b (patch)
tree514d119f9b28a549f0a74a9bf155e1defe856fd4 /libstdc++-v3/testsuite/experimental/string_view/operations/compare
parentda78abba75aabb78383a5116a8899e932eb648ba (diff)
downloadgcc-2fd2d470862f7a6aa1dbb6184ed1863202d59e0b.tar.gz
2013-11-16 Edward Smith-Rowland <3dw4rd@verizon.net>
Implement N3762 string_view: a non-owning reference to a string. * include/Makefile.am: Add string_view and string_view.tcc. * include/Makefile.in: Regenerate. * include/experimental/string_view: Implement basic_string_view. * include/experimental/string_view.tcc: Implement basic_string_view. * testsuite/experimental/string_view/capacity/1.cc: New. * testsuite/experimental/string_view/cons/char/1.cc: New. * testsuite/experimental/string_view/cons/char/2.cc: New. * testsuite/experimental/string_view/cons/char/3.cc: New. * testsuite/experimental/string_view/cons/wchar_t/1.cc: New. * testsuite/experimental/string_view/cons/wchar_t/2.cc: New. * testsuite/experimental/string_view/cons/wchar_t/3.cc: New. * testsuite/experimental/string_view/element_access/char/1.cc: New. * testsuite/experimental/string_view/element_access/char/2.cc: New. * testsuite/experimental/string_view/element_access/char/empty.cc: New. * testsuite/experimental/string_view/element_access/char/front_back.cc: New. * testsuite/experimental/string_view/element_access/wchar_t/1.cc: New. * testsuite/experimental/string_view/element_access/wchar_t/2.cc: New. * testsuite/experimental/string_view/element_access/wchar_t/empty.cc: New. * testsuite/experimental/string_view/element_access/wchar_t/ front_back.cc: New. * testsuite/experimental/string_view/include.cc: New. * testsuite/experimental/string_view/inserters/char/1.cc: New. * testsuite/experimental/string_view/inserters/char/2.cc: New. * testsuite/experimental/string_view/inserters/char/3.cc: New. * testsuite/experimental/string_view/inserters/pod/10081-out.cc: New. * testsuite/experimental/string_view/inserters/wchar_t/1.cc: New. * testsuite/experimental/string_view/inserters/wchar_t/2.cc: New. * testsuite/experimental/string_view/inserters/wchar_t/3.cc: New. * testsuite/experimental/string_view/literals/types.cc: New. * testsuite/experimental/string_view/literals/values.cc: New. * testsuite/experimental/string_view/modifiers/remove_prefix/char/1.cc: New. * testsuite/experimental/string_view/modifiers/remove_prefix/wchar_t/ 1.cc: New. * testsuite/experimental/string_view/modifiers/remove_suffix/char/1.cc: New. * testsuite/experimental/string_view/modifiers/remove_suffix/wchar_t/ 1.cc: New. * testsuite/experimental/string_view/operations/compare/char/1.cc: New. * testsuite/experimental/string_view/operations/compare/char/13650.cc: New. * testsuite/experimental/string_view/operations/compare/wchar_t/1.cc: New. * testsuite/experimental/string_view/operations/compare/wchar_t/ 13650.cc: New. * testsuite/experimental/string_view/operations/data/char/1.cc: New. * testsuite/experimental/string_view/operations/data/wchar_t/1.cc: New. * testsuite/experimental/string_view/operations/find/char/1.cc: New. * testsuite/experimental/string_view/operations/find/char/2.cc: New. * testsuite/experimental/string_view/operations/find/char/3.cc: New. * testsuite/experimental/string_view/operations/find/char/4.cc: New. * testsuite/experimental/string_view/operations/find/wchar_t/1.cc: New. * testsuite/experimental/string_view/operations/find/wchar_t/2.cc: New. * testsuite/experimental/string_view/operations/find/wchar_t/3.cc: New. * testsuite/experimental/string_view/operations/find/wchar_t/4.cc: New. * testsuite/experimental/string_view/operations/rfind/char/1.cc: New. * testsuite/experimental/string_view/operations/rfind/char/2.cc: New. * testsuite/experimental/string_view/operations/rfind/char/3.cc: New. * testsuite/experimental/string_view/operations/rfind/wchar_t/1.cc: New. * testsuite/experimental/string_view/operations/rfind/wchar_t/2.cc: New. * testsuite/experimental/string_view/operations/rfind/wchar_t/3.cc: New. * testsuite/experimental/string_view/operations/substr/char/1.cc: New. * testsuite/experimental/string_view/operations/substr/wchar_t/1.cc: New. * testsuite/experimental/string_view/operators/char/2.cc: New. * testsuite/experimental/string_view/operators/wchar_t/2.cc: New. * testsuite/experimental/string_view/range_access/char/1.cc: New. * testsuite/experimental/string_view/range_access/wchar_t/1.cc: New. * testsuite/experimental/string_view/requirements/ explicit_instantiation/1.cc: New. * testsuite/experimental/string_view/requirements/ explicit_instantiation/char/1.cc: New. * testsuite/experimental/string_view/requirements/ explicit_instantiation/char16_t/1.cc: New. * testsuite/experimental/string_view/requirements/ explicit_instantiation/char32_t/1.cc: New. * testsuite/experimental/string_view/requirements/ explicit_instantiation/wchar_t/1.cc: New. * testsuite/experimental/string_view/requirements/typedefs.cc: New. * testsuite/experimental/string_view/types/1.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@204902 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite/experimental/string_view/operations/compare')
-rw-r--r--libstdc++-v3/testsuite/experimental/string_view/operations/compare/char/1.cc134
-rw-r--r--libstdc++-v3/testsuite/experimental/string_view/operations/compare/char/13650.cc50
-rw-r--r--libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/1.cc134
-rw-r--r--libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/13650.cc50
4 files changed, 368 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/experimental/string_view/operations/compare/char/1.cc b/libstdc++-v3/testsuite/experimental/string_view/operations/compare/char/1.cc
new file mode 100644
index 00000000000..7fcbf657693
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/string_view/operations/compare/char/1.cc
@@ -0,0 +1,134 @@
+// { dg-options "-std=gnu++1y" }
+
+// Copyright (C) 2013 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view::compare
+// int compare(const basic_string_view& str) const;
+// int compare(size_type pos1, size_type n1, const basic_string_view& str) const;
+// int compare(size_type pos1, size_type n1, const basic_string_view& str,
+// size_type pos2, size_type n2) const;
+// int compare(const charT* s) const;
+// int compare(size_type pos1, size_type n1,
+// const charT* s, size_type n2 = npos) const;
+
+// NB compare should be thought of as a lexographical compare, ie how
+// things would be sorted in a dictionary.
+
+#include <experimental/string_view>
+#include <cstring>
+#include <testsuite_hooks.h>
+
+enum want_value {lt=0, z=1, gt=2};
+
+int
+test_value(int result, want_value expected);
+
+int
+test_value(int result, want_value expected)
+{
+ bool test [[gnu::unused]] = true;
+ bool pass = false;
+
+ switch (expected) {
+ case lt:
+ if (result < 0)
+ pass = true;
+ break;
+ case z:
+ if (!result)
+ pass = true;
+ break;
+ case gt:
+ if (result > 0)
+ pass = true;
+ break;
+ default:
+ pass = false; //should not get here
+ }
+ VERIFY(pass);
+ return 0;
+}
+
+
+int
+test01()
+{
+ using namespace std::experimental;
+
+ string_view str_0("costa rica");
+ string_view str_1("costa marbella");
+ string_view str_2;
+
+ //sanity check
+ test_value(strcmp("costa marbella", "costa rica"), lt);
+ test_value(strcmp("costa rica", "costa rica"), z);
+ test_value(strcmp(str_1.data(), str_0.data()), lt);
+ test_value(strcmp(str_0.data(), str_1.data()), gt);
+ test_value(strncmp(str_1.data(), str_0.data(), 6), z);
+ test_value(strncmp(str_1.data(), str_0.data(), 14), lt);
+ test_value(memcmp(str_1.data(), str_0.data(), 6), z);
+ test_value(memcmp(str_1.data(), str_0.data(), 14), lt);
+ test_value(memcmp("costa marbella", "costa rica", 14), lt);
+
+ // int compare(const basic_string_view& str) const;
+ test_value(str_0.compare(str_1), gt); //because r>m
+ test_value(str_1.compare(str_0), lt); //because m<r
+ str_2 = str_0;
+ test_value(str_2.compare(str_0), z);
+ str_2 = "cost";
+ test_value(str_2.compare(str_0), lt);
+ str_2 = "costa ricans";
+ test_value(str_2.compare(str_0), gt);
+
+ // int compare(size_type pos1, size_type n1, const basic_string_view& str) const;
+ test_value(str_1.compare(0, 6, str_0), lt);
+ str_2 = "cost";
+ test_value(str_1.compare(0, 4, str_2), z);
+ test_value(str_1.compare(0, 5, str_2), gt);
+
+ // int compare(size_type pos1, size_type n1, const basic_string_view& str,
+ // size_type pos2, size_type n2) const;
+ test_value(str_1.compare(0, 6, str_0, 0, 6), z);
+ test_value(str_1.compare(0, 7, str_0, 0, 7), lt);
+ test_value(str_0.compare(0, 7, str_1, 0, 7), gt);
+
+ // int compare(const charT* s) const;
+ test_value(str_0.compare("costa marbella"), gt);
+ test_value(str_1.compare("costa rica"), lt);
+ str_2 = str_0;
+ test_value(str_2.compare("costa rica"), z);
+ test_value(str_2.compare("cost"), gt);
+ test_value(str_2.compare("costa ricans"), lt);
+
+ // int compare(size_type pos, size_type n1, const charT* str,
+ // size_type n2 = npos) const;
+ test_value(str_1.compare(0, 6, "costa rica", 0, 6), z);
+ test_value(str_1.compare(0, 7, "costa rica", 0, 7), lt);
+ test_value(str_0.compare(0, 7, "costa marbella", 0, 7), gt);
+
+ return 0;
+}
+
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/experimental/string_view/operations/compare/char/13650.cc b/libstdc++-v3/testsuite/experimental/string_view/operations/compare/char/13650.cc
new file mode 100644
index 00000000000..5ae3c4cc6a1
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/string_view/operations/compare/char/13650.cc
@@ -0,0 +1,50 @@
+// { dg-options "-std=gnu++1y" }
+
+// Copyright (C) 2013 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view::compare [lib.string_view::compare]
+
+#include <experimental/string_view>
+#include <testsuite_hooks.h>
+
+// libstdc++/13650
+void
+test01()
+{
+ using namespace std::experimental;
+ bool test [[gnu::unused]] = true;
+
+ const char lit_01[]{ 'w', 'e', '\0', 'r', 'd' };
+ const char lit_02[]{ 'w', 'e', 'i', '\0', 'd' };
+
+ const char lit_ref_a[]{ 'w', 'e', '\0', 'q', 'd' };
+ const string_view str_a(lit_ref_a, 5);
+ VERIFY( str_a.compare(0, 5, lit_01, 5) < 0 );
+
+ const char lit_ref_b[]{ 'w', 'e', 'i' };
+ const string_view str_b(lit_ref_b, 3);
+ VERIFY( str_b.compare(0, 3, lit_02, 5) < 0 );
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/1.cc b/libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/1.cc
new file mode 100644
index 00000000000..4d01ebe38ce
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/1.cc
@@ -0,0 +1,134 @@
+// { dg-options "-std=gnu++1y" }
+
+// Copyright (C) 2013 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view::compare
+// int compare(const basic_string_view& str) const;
+// int compare(size_type pos1, size_type n1, const basic_string_view& str) const;
+// int compare(size_type pos1, size_type n1, const basic_string_view& str,
+// size_type pos2, size_type n2) const;
+// int compare(const charT* s) const;
+// int compare(size_type pos1, size_type n1,
+// const charT* s, size_type n2 = npos) const;
+
+// NB compare should be thought of as a lexographical compare, ie how
+// things would be sorted in a dictionary.
+
+#include <experimental/string_view>
+#include <testsuite_hooks.h>
+
+enum want_value {lt=0, z=1, gt=2};
+
+int
+test_value(int result, want_value expected);
+
+int
+test_value(int result, want_value expected)
+{
+ bool test [[gnu::unused]] = true;
+ bool pass = false;
+
+ switch (expected) {
+ case lt:
+ if (result < 0)
+ pass = true;
+ break;
+ case z:
+ if (!result)
+ pass = true;
+ break;
+ case gt:
+ if (result > 0)
+ pass = true;
+ break;
+ default:
+ pass = false; //should not get here
+ }
+
+ VERIFY(pass);
+ return 0;
+}
+
+
+int
+test01()
+{
+ using namespace std::experimental;
+
+ wstring_view str_0(L"costa rica");
+ wstring_view str_1(L"costa marbella");
+ wstring_view str_2;
+
+ //sanity check
+ test_value(wcscmp(L"costa marbella", L"costa rica"), lt);
+ test_value(wcscmp(L"costa rica", L"costa rica"), z);
+ test_value(wcscmp(str_1.data(), str_0.data()), lt);
+ test_value(wcscmp(str_0.data(), str_1.data()), gt);
+ test_value(wcsncmp(str_1.data(), str_0.data(), 6), z);
+ test_value(wcsncmp(str_1.data(), str_0.data(), 14), lt);
+ test_value(wmemcmp(str_1.data(), str_0.data(), 6), z);
+ test_value(wmemcmp(str_1.data(), str_0.data(), 14), lt);
+ test_value(wmemcmp(L"costa marbella", L"costa rica", 14), lt);
+
+ // int compare(const basic_string_view& str) const;
+ test_value(str_0.compare(str_1), gt); //because r>m
+ test_value(str_1.compare(str_0), lt); //because m<r
+ str_2 = str_0;
+ test_value(str_2.compare(str_0), z);
+ str_2 = L"cost";
+ test_value(str_2.compare(str_0), lt);
+ str_2 = L"costa ricans";
+ test_value(str_2.compare(str_0), gt);
+
+ // int compare(size_type pos1, size_type n1, const basic_string_view& str) const;
+ test_value(str_1.compare(0, 6, str_0), lt);
+ str_2 = L"cost";
+ test_value(str_1.compare(0, 4, str_2), z);
+ test_value(str_1.compare(0, 5, str_2), gt);
+
+ // int compare(size_type pos1, size_type n1, const basic_string_view& str,
+ // size_type pos2, size_type n2) const;
+ test_value(str_1.compare(0, 6, str_0, 0, 6), z);
+ test_value(str_1.compare(0, 7, str_0, 0, 7), lt);
+ test_value(str_0.compare(0, 7, str_1, 0, 7), gt);
+
+ // int compare(const charT* s) const;
+ test_value(str_0.compare(L"costa marbella"), gt);
+ test_value(str_1.compare(L"costa rica"), lt);
+ str_2 = str_0;
+ test_value(str_2.compare(L"costa rica"), z);
+ test_value(str_2.compare(L"cost"), gt);
+ test_value(str_2.compare(L"costa ricans"), lt);
+
+ // int compare(size_type pos, size_type n1, const charT* str,
+ // size_type n2 = npos) const;
+ test_value(str_1.compare(0, 6, L"costa rica", 0, 6), z);
+ test_value(str_1.compare(0, 7, L"costa rica", 0, 7), lt);
+ test_value(str_0.compare(0, 7, L"costa marbella", 0, 7), gt);
+
+ return 0;
+}
+
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/13650.cc b/libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/13650.cc
new file mode 100644
index 00000000000..82a4677a9ee
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/13650.cc
@@ -0,0 +1,50 @@
+// { dg-options "-std=gnu++1y" }
+
+// Copyright (C) 2013 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view::compare [lib.string_view::compare]
+
+#include <experimental/string_view>
+#include <testsuite_hooks.h>
+
+// libstdc++/13650
+void
+test01()
+{
+ using namespace std::experimental;
+ bool test [[gnu::unused]] = true;
+
+ const wchar_t lit_01[] = { L'w', L'e', L'\0', L'r', L'd' };
+ const wchar_t lit_02[] = { L'w', L'e', L'i', L'\0', L'd' };
+
+ const wchar_t lit_ref_a[] = { L'w', L'e', L'\0', L'q', L'd' };
+ const wstring_view str_a(lit_ref_a, 5);
+ VERIFY( str_a.compare(0, 5, lit_01, 5) < 0 );
+
+ const wchar_t lit_ref_b[] = { L'w', L'e', L'i' };
+ const wstring_view str_b(lit_ref_b, 3);
+ VERIFY( str_b.compare(0, 3, lit_02, 5) < 0 );
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}