MCPcopy Create free account
hub / github.com/boostorg/json / testElementAccess

Method testElementAccess

test/string.cpp:1018–1181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1016 }
1017
1018 void
1019 testElementAccess()
1020 {
1021 test_vectors const t;
1022
1023 string s1(t.v1);
1024 string s2(t.v2);
1025 auto const& cs1(s1);
1026 auto const& cs2(s2);
1027
1028 // at(size_type)
1029 {
1030 BOOST_TEST(s1.at(1) == 'b');
1031 s1.at(1) = '*';
1032 BOOST_TEST(s1.at(1) == '*');
1033 s1.at(1) = 'b';
1034 BOOST_TEST(s1.at(1) == 'b');
1035
1036 BOOST_TEST(s2.at(1) == 'B');
1037 s2.at(1) = '*';
1038 BOOST_TEST(s2.at(1) == '*');
1039 s2.at(1) = 'B';
1040 BOOST_TEST(s2.at(1) == 'B');
1041
1042 BOOST_TEST_THROWS_WITH_LOCATION( s1.at(s2.size()) );
1043 }
1044
1045 // at(size_type) const
1046 {
1047 BOOST_TEST(cs1.at(1) == 'b');
1048 BOOST_TEST(cs2.at(1) == 'B');
1049
1050 BOOST_TEST_THROWS_WITH_LOCATION( cs1.at(cs2.size()) );
1051 }
1052
1053 // try_at(size_type)
1054 {
1055 s1 = t.v1;
1056 s2 = t.v2;
1057 BOOST_TEST( *s1.try_at(1) == 'b' );
1058 *s1.try_at(1) = '*';
1059 BOOST_TEST( *s1.try_at(1) == '*' );
1060 *s1.try_at(1) = 'b';
1061 BOOST_TEST( *s1.try_at(1) == 'b' );
1062
1063 BOOST_TEST( *s2.try_at(1) == 'B' );
1064 *s2.try_at(1) = '*';
1065 BOOST_TEST( *s2.try_at(1) == '*' );
1066 *s2.try_at(1) = 'B';
1067 BOOST_TEST( *s2.try_at(1) == 'B' );
1068
1069 system::error_code const ec = s1.try_at(s2.size()).error();
1070 BOOST_TEST( ec == error::out_of_range );
1071 BOOST_TEST( ec.has_location() );
1072 }
1073
1074 // try_at(size_type) const
1075 {

Callers

nothing calls this directly

Calls 5

string_viewClass · 0.85
c_strMethod · 0.80
subviewMethod · 0.80
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected