From 6a3a4afa4f849b4a17ee0a2f113db915be8b9cc4 Mon Sep 17 00:00:00 2001 From: ilor <kailoran@gmail.com> Date: Thu, 25 Nov 2010 14:23:50 +0100 Subject: [PATCH] make Tagset::parse_symbol throw on invalid strings, update tests and code, bump version to 1.0.1 --- libcorpus2/CMakeLists.txt | 2 +- libcorpus2/tagset.cpp | 5 ++++- libcorpus2/tagset.h | 2 +- tests/tag_split.cpp | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libcorpus2/CMakeLists.txt b/libcorpus2/CMakeLists.txt index 551cf96..bd66f8d 100644 --- a/libcorpus2/CMakeLists.txt +++ b/libcorpus2/CMakeLists.txt @@ -3,7 +3,7 @@ PROJECT(corpus2) set(corpus2_ver_major "1") set(corpus2_ver_minor "0") -set(corpus2_ver_patch "0") +set(corpus2_ver_patch "1") if(NOT LIBCORPUS2_SRC_DATA_DIR) diff --git a/libcorpus2/tagset.cpp b/libcorpus2/tagset.cpp index 4cc6881..8f3a4f6 100644 --- a/libcorpus2/tagset.cpp +++ b/libcorpus2/tagset.cpp @@ -122,7 +122,10 @@ Tag Tagset::parse_symbol(const std::string& s) const return Tag(0, m); } m = get_value_mask(s); - return Tag(0, m); + if (m.any()) { + return Tag(0, m); + } + throw TagParseError("Not a tagset symbol", s, "", id_string()); } void Tagset::parse_tag(const string_range &s, bool allow_extra, diff --git a/libcorpus2/tagset.h b/libcorpus2/tagset.h index b6e1c1a..f413d56 100644 --- a/libcorpus2/tagset.h +++ b/libcorpus2/tagset.h @@ -129,7 +129,7 @@ public: * The resulting tags will usually be invalid as standalone tags, so * there is no validation performed. * - * An invalid string will result in a null tag being returned. + * An invalid string will result in a TagParseError exception. */ Tag parse_symbol(const std::string& s) const; diff --git a/tests/tag_split.cpp b/tests/tag_split.cpp index 098ef7a..f474931 100644 --- a/tests/tag_split.cpp +++ b/tests/tag_split.cpp @@ -242,6 +242,7 @@ BOOST_FIXTURE_TEST_CASE( symbols, F ) t = tagset->parse_symbol("C"); BOOST_CHECK_EQUAL(tagset->tag_to_symbol_string(t), "C"); BOOST_CHECK(tagset->tag_to_symbol_string(t, false) != "C"); + BOOST_CHECK_THROW(tagset->parse_symbol("asdf"), Corpus2::TagParseError); } BOOST_AUTO_TEST_SUITE_END() -- GitLab