Line data Source code
1 : // Author(s): Wieger Wesselink 2 : // Copyright: see the accompanying file COPYING or copy at 3 : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING 4 : // 5 : // Distributed under the Boost Software License, Version 1.0. 6 : // (See accompanying file LICENSE_1_0.txt or copy at 7 : // http://www.boost.org/LICENSE_1_0.txt) 8 : // 9 : 10 : #include "mcrl2/utilities/text_utility.h" 11 : 12 : #define BOOST_AUTO_TEST_MAIN 13 : #include <boost/test/included/unit_test.hpp> 14 : 15 : using namespace mcrl2; 16 : 17 : std::string TEXT1 = 18 : "abc % afdsd \n" 19 : "% \n" 20 : "% \n" 21 : "ddasdfsd%adsfs%-\n" 22 : ; 23 : 24 : std::string TEXT2 = 25 : "abc \n" 26 : "\n" 27 : "\n" 28 : "ddasdfsd\n" 29 : ; 30 : 31 2 : BOOST_AUTO_TEST_CASE(test_remove_comments) 32 : { 33 1 : std::string text = utilities::remove_comments(TEXT1); 34 1 : BOOST_CHECK(text == TEXT2); 35 1 : } 36 : 37 : std::string TEXT3 = 38 : "abcdef gh \n" 39 : "c\n" 40 : "\n" 41 : "abcde ghi" 42 : ; 43 : 44 : std::string TEXT4 = 45 : "abcde\n" 46 : "f gh\n" 47 : "c\n" 48 : "\n" 49 : "abcde\n" 50 : "ghi" 51 : ; 52 : 53 2 : BOOST_AUTO_TEST_CASE(test_word_wrap) 54 : { 55 1 : std::string text = utilities::word_wrap_text(TEXT3, 5); 56 1 : BOOST_CHECK(text == TEXT4); 57 1 : } 58 : 59 2 : BOOST_AUTO_TEST_CASE(test_number2string) 60 : { 61 1 : BOOST_CHECK(utilities::number2string(0) == "0"); 62 1 : BOOST_CHECK(utilities::number2string(1) == "1"); 63 1 : BOOST_CHECK(utilities::number2string(10) == "10"); 64 1 : BOOST_CHECK(utilities::number2string(123456789) == "123456789"); 65 1 : } 66 : 67 2 : BOOST_AUTO_TEST_CASE(test_regex_split) 68 : { 69 3 : BOOST_CHECK(utilities::regex_split("a := b; \n", ":=") == std::vector<std::string>({ "a", "b;" })); 70 5 : BOOST_CHECK(utilities::regex_split("a+b*c/d ", "[+*/]") == std::vector<std::string>({ "a", "b", "c", "d" })); 71 1 : }