From 87821c53c3a73d3e35a0e50a7c159d9aa5d6b253 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 14 Nov 2018 14:59:30 +0100 Subject: Isolating files shared between Yul- and Solidity language frontend. --- test/liblangutil/SourceLocation.cpp | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/liblangutil/SourceLocation.cpp (limited to 'test/liblangutil/SourceLocation.cpp') diff --git a/test/liblangutil/SourceLocation.cpp b/test/liblangutil/SourceLocation.cpp new file mode 100644 index 00000000..29cfb6a0 --- /dev/null +++ b/test/liblangutil/SourceLocation.cpp @@ -0,0 +1,50 @@ +/* + This file is part of solidity. + + solidity 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 of the License, or + (at your option) any later version. + + solidity 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 solidity. If not, see . +*/ +/** + * @author Yoichi Hirai + * @date 2016 + * Unit tests for the SourceLocation class. + */ + +#include + +#include + +namespace dev +{ +namespace solidity +{ +namespace test +{ + +BOOST_AUTO_TEST_SUITE(SourceLocationTest) + +BOOST_AUTO_TEST_CASE(test_fail) +{ + BOOST_CHECK(SourceLocation() == SourceLocation()); + BOOST_CHECK(SourceLocation(0, 3, std::make_shared("sourceA")) != SourceLocation(0, 3, std::make_shared("sourceB"))); + BOOST_CHECK(SourceLocation(0, 3, std::make_shared("source")) == SourceLocation(0, 3, std::make_shared("source"))); + BOOST_CHECK(SourceLocation(3, 7, std::make_shared("source")).contains(SourceLocation(4, 6, std::make_shared("source")))); + BOOST_CHECK(!SourceLocation(3, 7, std::make_shared("sourceA")).contains(SourceLocation(4, 6, std::make_shared("sourceB")))); + BOOST_CHECK(SourceLocation(3, 7, std::make_shared("sourceA")) < SourceLocation(4, 6, std::make_shared("sourceB"))); +} + +BOOST_AUTO_TEST_SUITE_END() + +} +} +} // end namespaces -- cgit v1.2.3 From d67322a1861d60a88151f7c25d6c3478a9a39acf Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 14 Nov 2018 17:11:55 +0100 Subject: Introduce namespace `langutil` in liblangutil directory. Also: - Use {}-style list initialisation for SourceLocation construction - Introduce new system includes - Changes the API of the Scanner to take source as value (with move) as opposed to as a reference --- test/liblangutil/SourceLocation.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'test/liblangutil/SourceLocation.cpp') diff --git a/test/liblangutil/SourceLocation.cpp b/test/liblangutil/SourceLocation.cpp index 29cfb6a0..ac7a2173 100644 --- a/test/liblangutil/SourceLocation.cpp +++ b/test/liblangutil/SourceLocation.cpp @@ -24,9 +24,7 @@ #include -namespace dev -{ -namespace solidity +namespace langutil { namespace test { @@ -45,6 +43,5 @@ BOOST_AUTO_TEST_CASE(test_fail) BOOST_AUTO_TEST_SUITE_END() -} } } // end namespaces -- cgit v1.2.3 From c48a5264be4221873fe02cac57f6a41a32010fea Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 28 Nov 2018 16:19:22 +0100 Subject: liblangutil: SourceLocation: adds (shared) pointer to underlying CharStream source, eliminating sourceName Also, adapted affecting code to those changes. --- test/liblangutil/SourceLocation.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'test/liblangutil/SourceLocation.cpp') diff --git a/test/liblangutil/SourceLocation.cpp b/test/liblangutil/SourceLocation.cpp index ac7a2173..ef4103da 100644 --- a/test/liblangutil/SourceLocation.cpp +++ b/test/liblangutil/SourceLocation.cpp @@ -33,12 +33,16 @@ BOOST_AUTO_TEST_SUITE(SourceLocationTest) BOOST_AUTO_TEST_CASE(test_fail) { + auto const source = std::make_shared("", "source"); + auto const sourceA = std::make_shared("", "sourceA"); + auto const sourceB = std::make_shared("", "sourceB"); + BOOST_CHECK(SourceLocation() == SourceLocation()); - BOOST_CHECK(SourceLocation(0, 3, std::make_shared("sourceA")) != SourceLocation(0, 3, std::make_shared("sourceB"))); - BOOST_CHECK(SourceLocation(0, 3, std::make_shared("source")) == SourceLocation(0, 3, std::make_shared("source"))); - BOOST_CHECK(SourceLocation(3, 7, std::make_shared("source")).contains(SourceLocation(4, 6, std::make_shared("source")))); - BOOST_CHECK(!SourceLocation(3, 7, std::make_shared("sourceA")).contains(SourceLocation(4, 6, std::make_shared("sourceB")))); - BOOST_CHECK(SourceLocation(3, 7, std::make_shared("sourceA")) < SourceLocation(4, 6, std::make_shared("sourceB"))); + BOOST_CHECK(SourceLocation(0, 3, sourceA) != SourceLocation(0, 3, sourceB)); + BOOST_CHECK(SourceLocation(0, 3, source) == SourceLocation(0, 3, source)); + BOOST_CHECK(SourceLocation(3, 7, source).contains(SourceLocation(4, 6, source))); + BOOST_CHECK(!SourceLocation(3, 7, sourceA).contains(SourceLocation(4, 6, sourceB))); + BOOST_CHECK(SourceLocation(3, 7, sourceA) < SourceLocation(4, 6, sourceB)); } BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3