Skip to content
Snippets Groups Projects
Select Git revision
  • 5a44bee85b83d30d6f7633f3d5616ab51c8d1c16
  • master default protected
  • vertical_relations
  • lu_without_semantic_frames
  • hierarchy
  • additional-unification-filters
  • v0.1.1
  • v0.1.0
  • v0.0.9
  • v0.0.8
  • v0.0.7
  • v0.0.6
  • v0.0.5
  • v0.0.4
  • v0.0.3
  • v0.0.2
  • v0.0.1
17 results

apps.py

Blame
  • regex.cpp 1.75 KiB
    #include <boost/test/unit_test.hpp>
    #include <boost/bind.hpp>
    #include <boost/shared_ptr.hpp>
    #include <libcorpus2/sentence.h>
    
    #include <libwccl/ops/functions/constant.h>
    #include <libwccl/ops/functions/bool/predicates/regex.h>
    #include <libwccl/values/bool.h>
    #include <libwccl/values/strset.h>
    #include <libwccl/sentencecontext.h>
    #include <unicode/unistr.h>
    
    using namespace Wccl;
    
    BOOST_AUTO_TEST_SUITE(regexing)
    
    struct RegexFix
    {
    	RegexFix()
    		: sc(boost::make_shared<Corpus2::Sentence>()),
    		  tagset(),
    		  cx(sc, boost::make_shared<Variables>())
    	{
    	}
    	SentenceContext sc;
    	Corpus2::Tagset tagset;
    	FunExecContext cx;
    };
    
    BOOST_FIXTURE_TEST_CASE(positive_sanity_check, RegexFix)
    {
    	StrSet sanity;
    	sanity.insert("word");
    	boost::shared_ptr<Function<StrSet> > sanity_expr(new Constant<StrSet>(sanity));
    	Regex r(sanity_expr, "word");
    	BOOST_CHECK(r.apply(cx)->get_value());
    }
    
    BOOST_FIXTURE_TEST_CASE(negative_sanity_check, RegexFix)
    {
    	StrSet sanity;
    	sanity.insert("word");
    	boost::shared_ptr<Function<StrSet> > sanity_expr(new Constant<StrSet>(sanity));
    	Regex r(sanity_expr, "Word");
    	BOOST_CHECK(!r.apply(cx)->get_value());
    }
    
    //TODO: need more regex tests...
    
    //------------ To string ----------
    
    BOOST_FIXTURE_TEST_CASE(regex_tostring, RegexFix)
    {
    	StrSet sanity;
    	sanity.insert("word");
    	boost::shared_ptr<Function<StrSet> > sanity_expr(new Constant<StrSet>(sanity));
    	Regex r(sanity_expr, "Word");
    	BOOST_CHECK_EQUAL("regex([\"word\"], \"Word\")", r.to_string(tagset));
    }
    
    BOOST_AUTO_TEST_CASE(regex_to_raw_string)
    {
    	StrSet sanity;
    	sanity.insert("word");
    	boost::shared_ptr<Function<StrSet> > sanity_expr(new Constant<StrSet>(sanity));
    	Regex r(sanity_expr, "Word");
    	BOOST_CHECK_EQUAL("regex([\"word\"], \"Word\")", r.to_raw_string());
    }
    
    BOOST_AUTO_TEST_SUITE_END()