• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ spirit_test类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中spirit_test的典型用法代码示例。如果您正苦于以下问题:C++ spirit_test类的具体用法?C++ spirit_test怎么用?C++ spirit_test使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了spirit_test类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

int
main()
{
    namespace karma = boost::spirit::karma;
    using spirit_test::test;
    using namespace boost::spirit;
    using namespace boost::spirit::karma;
    namespace phx = boost::phoenix;

    {
        BOOST_TEST(test("123", karma::lazy(phx::val(int_)), 123));
    }

    {
        int result = 123;
        BOOST_TEST(test("123", karma::lazy(phx::val(int_))[_1 = phx::ref(result)]));
    }

//     {
//         typedef spirit_test::output_iterator<char>::type outiter_type;
//         rule<outiter_type, void(std::string)> r;
// 
//         r = char_('<') << karma::lazy(_r1) << '>' <<  "</" << karma::lazy(_r1) << '>';
// 
//         std::string tag("tag"), foo("foo");
//         BOOST_TEST(test("<tag></tag>", r (phx::ref(tag))));
//         BOOST_TEST(!test("<foo></bar>", r (phx::ref(foo))));
//     }

    return boost::report_errors();
}
开发者ID:LancelotGHX,项目名称:Simula,代码行数:31,代码来源:lazy.cpp


示例2: main

int
main()
{
    using spirit_test::test_attr;
    using spirit_test::test;

    using boost::spirit::x3::rule;
    using boost::spirit::x3::int_;
    using boost::spirit::x3::with;

    { // injecting data into the context in the grammar

        int val = 0;
        auto r = rule<my_rule_class, char const*>() =
            '(' > int_ > ',' > int_ > ')'
            ;
        
        auto start =
            with<my_tag>(std::ref(val)) [ r ]
            ;

        BOOST_TEST(test("(123,456)", start));
        BOOST_TEST(!test("(abc,def)", start));
        BOOST_TEST(val == 2);
    }

    return boost::report_errors();
}
开发者ID:OggYiu,项目名称:rag-engine,代码行数:28,代码来源:with.cpp


示例3: main

int main () 
{
    using spirit_test::test;

    {
        using boost::spirit::karma::int_;

        data1 b(800, 600);
        BOOST_TEST(test("width: 800\nheight: 600\n", 
            "width: " << int_ << "\n" << "height: " << int_ << "\n", b));
    }

    {
        using boost::spirit::karma::char_;
        using boost::spirit::karma::string;

        data2 d("test");
        BOOST_TEST(test("data: test\n", "data: " << +char_ << "\n", d));
        BOOST_TEST(test("data: test\n", "data: " << string << "\n", d));
    }

    {
        using boost::spirit::karma::double_;

        BOOST_TEST(test("x=0.0\n", "x=" << double_ << "\n", data3(0)));
        BOOST_TEST(test("x=1.1\n", "x=" << double_ << "\n", data3(1.1)));
        BOOST_TEST(test("x=1.0e10\n", "x=" << double_ << "\n", data3(1e10)));

        BOOST_TEST(test("x=inf\n", "x=" << double_ << "\n", 
            data3(std::numeric_limits<double>::infinity())));
        if (std::numeric_limits<double>::has_quiet_NaN) {
            BOOST_TEST(test("x=nan\n", "x=" << double_ << "\n", 
                data3(std::numeric_limits<double>::quiet_NaN())));
        }
        if (std::numeric_limits<double>::has_signaling_NaN) {
            BOOST_TEST(test("x=nan\n", "x=" << double_ << "\n", 
                data3(std::numeric_limits<double>::signaling_NaN())));
        }
    }

    {
        using boost::spirit::karma::double_;
        using boost::spirit::karma::int_;
        using boost::spirit::karma::string;

        data4 d;
        d.b_ = 10;

        BOOST_TEST(test(
            "Testing: b: 10.0\n", 
            "Testing: " << -("a: " << int_ << "\n")
                        << -("b: " << double_ << "\n")
                        << -("c: " << string << "\n"), d));
    }

    return boost::report_errors();
}
开发者ID:0xDEC0DE8,项目名称:mcsema,代码行数:57,代码来源:regression_adapt_adt.cpp


示例4: main

int
main()
{
    using boost::spirit::x3::ascii::char_;
    using boost::spirit::x3::ascii::space;
    using boost::spirit::x3::lit;
    using spirit_test::test;
    using spirit_test::test_attr;

    // Basic tests
    {
        BOOST_TEST(test("b", char_ - 'a'));
        BOOST_TEST(!test("a", char_ - 'a'));
        BOOST_TEST(test("/* abcdefghijk */", "/*" >> *(char_ - "*/") >> "*/"));
        BOOST_TEST(!test("switch", lit("switch") - "switch"));
    }

    // Test attributes
    {
        char attr;
        BOOST_TEST(test_attr("xg", (char_ - 'g') >> 'g', attr));
        BOOST_TEST(attr == 'x');
    }

    // Test handling of container attributes
    {
        std::string attr;
        BOOST_TEST(test_attr("abcdefg", *(char_ - 'g') >> 'g', attr));
        BOOST_TEST(attr == "abcdef");
    }

    {
        using boost::spirit::x3::_attr;

        std::string s;

        BOOST_TEST(test(
            "/*abcdefghijk*/"
          , "/*" >> *(char_ - "*/")[([&](auto& ctx){ s += _attr(ctx); })] >> "*/"
        ));
        BOOST_TEST(s == "abcdefghijk");
        s.clear();

        BOOST_TEST(test(
            "    /*abcdefghijk*/"
          , "/*" >> *(char_ - "*/")[([&](auto& ctx){ s += _attr(ctx); })] >> "*/"
          , space
        ));
        BOOST_TEST(s == "abcdefghijk");
    }

    return boost::report_errors();
}
开发者ID:Cabriter,项目名称:abelkhan,代码行数:53,代码来源:difference.cpp


示例5: main

int
main()
{
    using spirit_test::test;
    using boost::spirit::int_;

    {
        BOOST_TEST((test("1234", &int_, false)));
        BOOST_TEST((!test("abcd", &int_)));
    }

    return boost::report_errors();
}
开发者ID:0xDEC0DE8,项目名称:mcsema,代码行数:13,代码来源:and_predicate.cpp


示例6: main

int
main()
{
    using spirit_test::test;
    using boost::spirit::x3::eol;

    {
        BOOST_TEST((test("\r\n", eol)));
        BOOST_TEST((test("\r", eol)));
        BOOST_TEST((test("\n", eol)));
        BOOST_TEST((!test("\n\r", eol)));
        BOOST_TEST((!test("", eol)));
    }

    return boost::report_errors();
}
开发者ID:fpelliccioni,项目名称:spirit_x3,代码行数:16,代码来源:eol.cpp


示例7: main

int
main()
{
    using spirit_test::test;
    using boost::spirit::x3::eoi;

    {
        BOOST_TEST((test("", eoi)));
        BOOST_TEST(!(test("x", eoi)));
    }

    {
        BOOST_TEST(what(eoi) == "eoi");
    }

    return boost::report_errors();
}
开发者ID:Cabriter,项目名称:abelkhan,代码行数:17,代码来源:eoi.cpp


示例8: main

int main()
{
    using spirit_test::test_attr;
    using spirit_test::test;

    using namespace boost::spirit::x3::ascii;
    using boost::spirit::x3::rule;
    using boost::spirit::x3::int_;
    using boost::spirit::x3::lit;


    { // synth attribute value-init

        std::string s;
        typedef rule<class r, std::string> rule_type;

        auto rdef = rule_type()
            = alpha                 [f()]
            ;

        BOOST_TEST(test_attr("abcdef", +rdef, s));
        BOOST_TEST(s == "abcdef");
    }

    { // synth attribute value-init

        std::string s;
        typedef rule<class r, std::string> rule_type;

        auto rdef = rule_type() =
            alpha /
               [](auto& ctx)
               {
                  _val(ctx) += _attr(ctx);
               }
            ;

        BOOST_TEST(test_attr("abcdef", +rdef, s));
        BOOST_TEST(s == "abcdef");
    }

    return boost::report_errors();
}
开发者ID:LancelotGHX,项目名称:Simula,代码行数:43,代码来源:rule3.cpp


示例9: main

int
main()
{
    using spirit_test::test;
    using namespace boost::spirit;

    {
        BOOST_TEST(test("", eps));
    }

    {   // test action

        using namespace boost::phoenix;
        BOOST_TEST(test("", eps(val(true))));
        BOOST_TEST(!test("", eps(val(false))));
    }

    return boost::report_errors();
}
开发者ID:coxlab,项目名称:boost_patched_for_objcplusplus,代码行数:19,代码来源:eps.cpp


示例10: main

int
main()
{
    using spirit_test::test;
    using spirit_test::test_attr;
    using boost::spirit::x3::ascii::space;
    using boost::spirit::x3::ascii::space_type;
    using boost::spirit::x3::ascii::char_;
    using boost::spirit::x3::ascii::alpha;
    using boost::spirit::x3::lexeme;
    using boost::spirit::x3::skip;
    using boost::spirit::x3::lit;

    {
        BOOST_TEST((test("a b c d", skip(space)[*char_])));
    }

    { // test attribute
        std::string s;
        BOOST_TEST((test_attr("a b c d", skip(space)[*char_], s)));
        BOOST_TEST(s == "abcd");
    }

    { // reskip
        BOOST_TEST((test("ab c d", lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']], space)));
        BOOST_TEST((test("abcd", lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']], space)));
        BOOST_TEST(!(test("a bcd", lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']], space)));

        BOOST_TEST((test("ab c d", lexeme[lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']]], space)));
        BOOST_TEST((test("abcd", lexeme[lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']]], space)));
        BOOST_TEST(!(test("a bcd", lexeme[lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']]], space)));
    }

    //~ { // lazy skip
        //~ using boost::phoenix::val;

        //~ BOOST_TEST((test("a b c d", skip(val(space))[*char_])));
    //~ }

    return boost::report_errors();
}
开发者ID:OggYiu,项目名称:rag-engine,代码行数:41,代码来源:skip.cpp


示例11: main

int
main()
{
    using spirit_test::test;
    using spirit_test::test_attr;
    using boost::spirit::qi::lit;
    using boost::spirit::qi::no_case;
    using boost::spirit::qi::char_;
    using boost::spirit::qi::encoding;
    namespace char_encoding = boost::spirit::char_encoding;

    encoding<char_encoding::iso8859_1> iso8859_1;

    { // test extended ASCII characters
        BOOST_TEST(test("\xC1", iso8859_1[no_case['\xE1']]));
        BOOST_TEST(test("\xC1", iso8859_1[no_case[char_('\xE1')]]));

        BOOST_TEST(test("\xC9", iso8859_1[no_case[char_("\xE5-\xEF")]]));
        BOOST_TEST(!test("\xFF", iso8859_1[no_case[char_("\xE5-\xEF")]]));

        BOOST_TEST(test("\xC1\xE1", iso8859_1[no_case["\xE1\xC1"]]));
        BOOST_TEST(test("\xC1\xE1", iso8859_1[no_case[lit("\xE1\xC1")]]));
    }

    return boost::report_errors();
}
开发者ID:boostorg,项目名称:spirit,代码行数:26,代码来源:encoding.cpp


示例12: main

int main()
{
    using spirit_test::test;
    using spirit_test::test_attr;
    using namespace boost::spirit::x3::ascii;
    using boost::spirit::x3::raw;
    using boost::spirit::x3::eps;
    using boost::spirit::x3::_attr;

    {
        boost::iterator_range<char const*> range;
        std::string str;
        BOOST_TEST((test_attr("spirit_test_123", raw[alpha >> *(alnum | '_')], range)));
        BOOST_TEST((std::string(range.begin(), range.end()) == "spirit_test_123"));
        BOOST_TEST((test_attr("  spirit", raw[*alpha], range, space)));
        BOOST_TEST((range.size() == 6));
    }

    {
        std::string str;
        BOOST_TEST((test_attr("spirit_test_123", raw[alpha >> *(alnum | '_')], str)));
        BOOST_TEST((str == "spirit_test_123"));
    }

    {
        boost::iterator_range<char const*> range;
        BOOST_TEST((test("x", raw[alpha])));
        BOOST_TEST((test_attr("x", raw[alpha], range)));
    }

    {
        boost::iterator_range<char const*> range;
        BOOST_TEST((test("x", raw[alpha][ ([&](auto& ctx){ range = _attr(ctx); }) ])));
        BOOST_TEST(range.size() == 1 && *range.begin() == 'x');
    }

    return boost::report_errors();
}
开发者ID:LancelotGHX,项目名称:Simula,代码行数:38,代码来源:raw.cpp


示例13: main

int main()
{
    namespace qi = boost::spirit::qi;
    namespace phoenix = boost::phoenix;
    using spirit_test::test_attr;

    {
        qi::rule<char const*, std::string()> r;
        r %= (+qi::char_)[phoenix::bind(&f, qi::_1)];

        std::string attr;
        BOOST_TEST(test_attr("abcdef", r, attr));
        BOOST_TEST(attr == "abcdef");
    }

    return boost::report_errors();
}
开发者ID:TheRyaz,项目名称:c_reading,代码行数:17,代码来源:actions2.cpp


示例14: main

int
main()
{
    using spirit_test::test_attr;
    namespace qi = boost::spirit::qi;

    using qi::attr;
    using qi::double_;

    {
        double d = 0.0;
        BOOST_TEST(test_attr("", attr(1.0), d) && d == 1.0);

        double d1 = 1.0;
        BOOST_TEST(test_attr("", attr(d1), d) && d == 1.0);

        std::pair<double, double> p;
        BOOST_TEST(test_attr("1.0", double_ >> attr(1.0), p) && 
            p.first == 1.0 && p.second == 1.0);

        char c = '\0';
        BOOST_TEST(test_attr("", attr('a'), c) && c == 'a');
        std::string str;
        BOOST_TEST(test_attr("", attr("test"), str) && str == "test");
    }

    {   // testing lazy constructs
        using boost::phoenix::val;
        using boost::phoenix::ref;

        double d = 0.0;
        BOOST_TEST(test_attr("", attr(val(1.0)), d) && d == 1.0);

        double d1 = 2.0;
        BOOST_TEST(test_attr("", attr(ref(d1)), d) && d == 2.0);
    }

    {
        std::string s;
        BOOST_TEST(test_attr("s", "s" >> qi::attr(std::string("123")), s) && 
            s == "123");
    }

    return boost::report_errors();
}
开发者ID:LancelotGHX,项目名称:Simula,代码行数:45,代码来源:attr.cpp


示例15: main

int
main()
{
    using spirit_test::test;
    using spirit_test::test_attr;
    using boost::spirit::qi::lit;
    using boost::spirit::qi::no_case;
    using boost::spirit::qi::char_;
    using boost::spirit::qi::encoding;
    namespace char_encoding = boost::spirit::char_encoding;

    encoding<char_encoding::iso8859_1> iso8859_1;

// needed for VC7.1 only
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
#pragma setlocale("french")
#endif

    {
        BOOST_TEST(test("Á", iso8859_1[no_case['á']]));
        BOOST_TEST(test("Á", iso8859_1[no_case[char_('á')]]));
    }

    {
        BOOST_TEST(test("É", iso8859_1[no_case[char_("å-ï")]]));
        BOOST_TEST(!test("ÿ", iso8859_1[no_case[char_("å-ï")]]));
    }

    {
        BOOST_TEST(test("Áá", iso8859_1[no_case["áÁ"]]));
        BOOST_TEST(test("Áá", iso8859_1[no_case[lit("áÁ")]]));
    }


#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
#pragma setlocale("")
#endif

    return boost::report_errors();
}
开发者ID:Alexander--,项目名称:Wesnoth-1.8-for-Android,代码行数:40,代码来源:encoding.cpp


示例16: main

int
main()
{
    using spirit_test::test_attr;
    using spirit_test::test;

    using namespace boost::spirit::ascii;
    using namespace boost::spirit::qi::labels;
    using boost::spirit::qi::locals;
    using boost::spirit::qi::rule;
    using boost::spirit::qi::int_;
    using boost::spirit::qi::uint_;
    using boost::spirit::qi::fail;
    using boost::spirit::qi::on_error;
    using boost::spirit::qi::debug;
    using boost::spirit::qi::lit;

    namespace phx = boost::phoenix;

    { // synth attribute value-init

        std::string s;
        rule<char const*, char()> r;
        r = alpha[_val += _1];
        BOOST_TEST(test_attr("abcdef", +r, s));
        BOOST_TEST(s == "abcdef");
    }

    { // auto rules aliasing tests

        char ch = '\0';
        rule<char const*, char()> a, b;
        a %= b;
        b %= alpha;

        BOOST_TEST(test("x", a[phx::ref(ch) = _1]));
        BOOST_TEST(ch == 'x');
        ch = '\0';
        BOOST_TEST(test_attr("z", a, ch)); // attribute is given.
        BOOST_TEST(ch == 'z');

        a = b;            // test deduced auto rule behavior
        b = alpha;

        ch = '\0';
        BOOST_TEST(test("x", a[phx::ref(ch) = _1]));
        BOOST_TEST(ch == 'x');
        ch = '\0';
        BOOST_TEST(test_attr("z", a, ch)); // attribute is given.
        BOOST_TEST(ch == 'z');
    }

    { // context (w/arg) tests

        char ch;
        rule<char const*, char(int)> a; // 1 arg
        a = alpha[_val = _1 + _r1];

        BOOST_TEST(test("x", a(phx::val(1))[phx::ref(ch) = _1]));
        BOOST_TEST(ch == 'x' + 1);

        BOOST_TEST(test_attr("a", a(1), ch)); // allow scalars as rule args too.
        BOOST_TEST(ch == 'a' + 1);

        rule<char const*, char(int, int)> b; // 2 args
        b = alpha[_val = _1 + _r1 + _r2];
        BOOST_TEST(test_attr("a", b(1, 2), ch));
        BOOST_TEST(ch == 'a' + 1 + 2);
    }

    { // context (w/ reference arg) tests

        char ch;
        rule<char const*, void(char&)> a; // 1 arg (reference)
        a = alpha[_r1 = _1];

        BOOST_TEST(test("x", a(phx::ref(ch))));
        BOOST_TEST(ch == 'x');
    }

    { // context (w/locals) tests

        rule<char const*, locals<char> > a; // 1 local
        a = alpha[_a = _1] >> char_(_a);
        BOOST_TEST(test("aa", a));
        BOOST_TEST(!test("ax", a));
    }

    { // context (w/args and locals) tests

        rule<char const*, void(int), locals<char> > a; // 1 arg + 1 local
        a = alpha[_a = _1 + _r1] >> char_(_a);
        BOOST_TEST(test("ab", a(phx::val(1))));
        BOOST_TEST(test("xy", a(phx::val(1))));
        BOOST_TEST(!test("ax", a(phx::val(1))));
    }

    { // void() has unused type (void == unused_type)

        std::pair<int, char> attr;
//.........这里部分代码省略.........
开发者ID:LancelotGHX,项目名称:Simula,代码行数:101,代码来源:rule3.cpp


示例17: main

int
main()
{
    using spirit_test::test;
    using spirit_test::test_attr;

    ///////////////////////////////////////////////////////////////////////////
    //  strict real number tests
    ///////////////////////////////////////////////////////////////////////////
    {
        using boost::spirit::x3::real_parser;
        using boost::spirit::x3::parse;
        using boost::spirit::x3::strict_ureal_policies;
        using boost::spirit::x3::strict_real_policies;

        real_parser<double, strict_ureal_policies<double> > strict_udouble;
        real_parser<double, strict_real_policies<double> > strict_double;
        double  d;

        BOOST_TEST(!test("1234", strict_udouble));
        BOOST_TEST(!test_attr("1234", strict_udouble, d));

        BOOST_TEST(test("1.2", strict_udouble));
        BOOST_TEST(test_attr("1.2", strict_udouble, d) && compare(d, 1.2));

        BOOST_TEST(!test("-1234", strict_double));
        BOOST_TEST(!test_attr("-1234", strict_double, d));

        BOOST_TEST(test("123.", strict_double));
        BOOST_TEST(test_attr("123.", strict_double, d) && compare(d, 123));

        BOOST_TEST(test("3.E6", strict_double));
        BOOST_TEST(test_attr("3.E6", strict_double, d) && compare(d, 3e6));

        real_parser<double, no_trailing_dot_policy<double> > notrdot_real;
        real_parser<double, no_leading_dot_policy<double> > nolddot_real;

        BOOST_TEST(!test("1234.", notrdot_real));          //  Bad trailing dot
        BOOST_TEST(!test(".1234", nolddot_real));          //  Bad leading dot
    }

    ///////////////////////////////////////////////////////////////////////////
    //  Special thousands separated numbers
    ///////////////////////////////////////////////////////////////////////////
    {
        using boost::spirit::x3::real_parser;
        using boost::spirit::x3::parse;
        real_parser<double, ts_real_policies<double> > ts_real;
        double  d;

        BOOST_TEST(test("123,456,789.01", ts_real));
        BOOST_TEST(test_attr("123,456,789.01", ts_real, d)
                && compare(d, 123456789.01));

        BOOST_TEST(test("12,345,678.90", ts_real));
        BOOST_TEST(test_attr("12,345,678.90", ts_real, d)
                && compare(d, 12345678.90));

        BOOST_TEST(test("1,234,567.89", ts_real));
        BOOST_TEST(test_attr("1,234,567.89", ts_real, d)
                && compare(d, 1234567.89));

        BOOST_TEST(!test("1234,567,890", ts_real));
        BOOST_TEST(!test("1,234,5678,9", ts_real));
        BOOST_TEST(!test("1,234,567.89e6", ts_real));
        BOOST_TEST(!test("1,66", ts_real));
    }

    return boost::report_errors();
}
开发者ID:Ed-von-Schleck,项目名称:spirit_x3,代码行数:70,代码来源:real3.cpp


示例18: main

int
main()
{
    using spirit_test::test;
    using spirit_test::test_attr;

    {
        using namespace boost::spirit::ascii;
        BOOST_TEST(test("1", alnum));
        BOOST_TEST(!test(" ", alnum));
        BOOST_TEST(!test("1", alpha));
        BOOST_TEST(test("x", alpha));
        BOOST_TEST(test(" ", blank));
        BOOST_TEST(!test("x", blank));
        BOOST_TEST(test("1", digit));
        BOOST_TEST(!test("x", digit));
        BOOST_TEST(test("a", lower));
        BOOST_TEST(!test("A", lower));
        BOOST_TEST(test("!", punct));
        BOOST_TEST(!test("x", punct));
        BOOST_TEST(test(" ", space));
        BOOST_TEST(test("\n", space));
        BOOST_TEST(test("\r", space));
        BOOST_TEST(test("\t", space));
        BOOST_TEST(test("A", upper));
        BOOST_TEST(!test("a", upper));
        BOOST_TEST(test("A", xdigit));
        BOOST_TEST(test("0", xdigit));
        BOOST_TEST(test("f", xdigit));
        BOOST_TEST(!test("g", xdigit));

        // should fail, not assert!
        // $$$ Removing this test for now $$$
        // BOOST_TEST(!test("\265", space));
    }

    {
        using namespace boost::spirit::ascii;
        BOOST_TEST(!test("1", ~alnum));
        BOOST_TEST(test(" ", ~alnum));
        BOOST_TEST(test("1", ~alpha));
        BOOST_TEST(!test("x", ~alpha));
        BOOST_TEST(!test(" ", ~blank));
        BOOST_TEST(test("x", ~blank));
        BOOST_TEST(!test("1", ~digit));
        BOOST_TEST(test("x", ~digit));
        BOOST_TEST(!test("a", ~lower));
        BOOST_TEST(test("A", ~lower));
        BOOST_TEST(!test("!", ~punct));
        BOOST_TEST(test("x", ~punct));
        BOOST_TEST(!test(" ", ~space));
        BOOST_TEST(!test("\n", ~space));
        BOOST_TEST(!test("\r", ~space));
        BOOST_TEST(!test("\t", ~space));
        BOOST_TEST(!test("A", ~upper));
        BOOST_TEST(test("a", ~upper));
        BOOST_TEST(!test("A", ~xdigit));
        BOOST_TEST(!test("0", ~xdigit));
        BOOST_TEST(!test("f", ~xdigit));
        BOOST_TEST(test("g", ~xdigit));
    }

    {
        // we use the hoisted qi namespace this time
        using namespace boost::spirit::qi::iso8859_1;
        BOOST_TEST(test("1", alnum));
        BOOST_TEST(!test(" ", alnum));
        BOOST_TEST(!test("1", alpha));
        BOOST_TEST(test("x", alpha));
        BOOST_TEST(test(" ", blank));
        BOOST_TEST(!test("x", blank));
        BOOST_TEST(test("1", digit));
        BOOST_TEST(!test("x", digit));
        BOOST_TEST(test("a", lower));
        BOOST_TEST(!test("A", lower));
        BOOST_TEST(test("!", punct));
        BOOST_TEST(!test("x", punct));
        BOOST_TEST(test(" ", space));
        BOOST_TEST(test("\n", space));
        BOOST_TEST(test("\r", space));
        BOOST_TEST(test("\t", space));
        BOOST_TEST(test("A", upper));
        BOOST_TEST(!test("a", upper));
        BOOST_TEST(test("A", xdigit));
        BOOST_TEST(test("0", xdigit));
        BOOST_TEST(test("f", xdigit));
        BOOST_TEST(!test("g", xdigit));

// needed for VC7.1 only
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
#pragma setlocale("german")
#endif
        BOOST_TEST(test("é", alpha));
        BOOST_TEST(test("é", lower));
        BOOST_TEST(!test("é", upper));
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
#pragma setlocale("")
#endif
    }

//.........这里部分代码省略.........
开发者ID:LancelotGHX,项目名称:Simula,代码行数:101,代码来源:char_class.cpp


示例19: main

int
main()
{
    using spirit_test::test;
    //~ using spirit_test::test_attr;
    //~ using spirit_test::print_info;

    {
        using namespace boost::spirit::x3::ascii;

        BOOST_TEST(test("x", 'x'));
        BOOST_TEST(test(L"x", L'x'));
        BOOST_TEST(!test("y", 'x'));
        BOOST_TEST(!test(L"y", L'x'));

        BOOST_TEST(test("x", char_));
        BOOST_TEST(test("x", char_('x')));
        BOOST_TEST(!test("x", char_('y')));
        //~ BOOST_TEST(test("x", char_('a', 'z')));
        //~ BOOST_TEST(!test("x", char_('0', '9')));

        BOOST_TEST(!test("x", ~char_));
        BOOST_TEST(!test("x", ~char_('x')));
        BOOST_TEST(test(" ", ~char_('x')));
        BOOST_TEST(test("X", ~char_('x')));
        //~ BOOST_TEST(!test("x", ~char_('b', 'y')));
        //~ BOOST_TEST(test("a", ~char_('b', 'y')));
        //~ BOOST_TEST(test("z", ~char_('b', 'y')));

        BOOST_TEST(test("x", ~~char_));
        BOOST_TEST(test("x", ~~char_('x')));
        BOOST_TEST(!test(" ", ~~char_('x')));
        BOOST_TEST(!test("X", ~~char_('x')));
        //~ BOOST_TEST(test("x", ~~char_('b', 'y')));
        //~ BOOST_TEST(!test("a", ~~char_('b', 'y')));
        //~ BOOST_TEST(!test("z", ~~char_('b', 'y')));
    }

    {
        using namespace boost::spirit::x3::ascii;

        BOOST_TEST(test("   x", 'x', space));
        BOOST_TEST(test(L"   x", L'x', space));

        BOOST_TEST(test("   x", char_, space));
        BOOST_TEST(test("   x", char_('x'), space));
        BOOST_TEST(!test("   x", char_('y'), space));
        //~ BOOST_TEST(test("   x", char_('a', 'z'), space));
        //~ BOOST_TEST(!test("   x", char_('0', '9'), space));
    }

    {
        using namespace boost::spirit::x3::standard_wide;

        BOOST_TEST(test(L"x", char_));
        BOOST_TEST(test(L"x", char_(L'x')));
        BOOST_TEST(!test(L"x", char_(L'y')));
        //~ BOOST_TEST(test(L"x", char_(L'a', L'z')));
        //~ BOOST_TEST(!test(L"x", char_(L'0', L'9')));

        BOOST_TEST(!test(L"x", ~char_));
        BOOST_TEST(!test(L"x", ~char_(L'x')));
        BOOST_TEST(test(L" ", ~char_(L'x')));
        BOOST_TEST(test(L"X", ~char_(L'x')));
        //~ BOOST_TEST(!test(L"x", ~char_(L'b', L'y')));
        //~ BOOST_TEST(test(L"a", ~char_(L'b', L'y')));
        //~ BOOST_TEST(test(L"z", ~char_(L'b', L'y')));

        BOOST_TEST(test(L"x", ~~char_));
        BOOST_TEST(test(L"x", ~~char_(L'x')));
        BOOST_TEST(!test(L" ", ~~char_(L'x')));
        BOOST_TEST(!test(L"X", ~~char_(L'x')));
        //~ BOOST_TEST(test(L"x", ~~char_(L'b', L'y')));
        //~ BOOST_TEST(!test(L"a", ~~char_(L'b', L'y')));
        //~ BOOST_TEST(!test(L"z", ~~char_(L'b', L'y')));
    }


    //~ {   // single char strings!
        //~ namespace ascii = boost::spirit::x3::ascii;
        //~ namespace wide = boost::spirit::x3::standard_wide;

        //~ BOOST_TEST(test("x", "x"));
        //~ BOOST_TEST(test(L"x", L"x"));
        //~ BOOST_TEST(test("x", ascii::char_("x")));
        //~ BOOST_TEST(test(L"x", wide::char_(L"x")));

        //~ BOOST_TEST(test("x", ascii::char_("a", "z")));
        //~ BOOST_TEST(test(L"x", ascii::char_(L"a", L"z")));
    //~ }

    //~ {
        //~ // chsets
        //~ namespace ascii = boost::spirit::x3::ascii;
        //~ namespace wide = boost::spirit::x3::standard_wide;

        //~ BOOST_TEST(test("x", ascii::char_("a-z")));
        //~ BOOST_TEST(!test("1", ascii::char_("a-z")));
        //~ BOOST_TEST(test("1", ascii::char_("a-z0-9")));

//.........这里部分代码省略.........
开发者ID:Ed-von-Schleck,项目名称:spirit_x3,代码行数:101,代码来源:char1.cpp


示例20: main

int main()
{
    using spirit_test::test_attr;
    using spirit_test::test;
    using spirit_test::binary_test;
    using spirit_test::binary_test_attr;

    using boost::spirit::qi::byte_;
    using boost::spirit::qi::word;
    using boost::spirit::qi::dword;
    using boost::spirit::qi::big_word;
    using boost::spirit::qi::big_dword;
    using boost::spirit::qi::little_word;
    using boost::spirit::qi::little_dword;
#ifdef BOOST_HAS_LONG_LONG
    using boost::spirit::qi::qword;
    using boost::spirit::qi::big_qword;
    using boost::spirit::qi::little_qword;
#endif
    using boost::spirit::qi::bin_float;
    using boost::spirit::qi::big_bin_float;
    using boost::spirit::qi::little_bin_float;
    using boost::spirit::qi::bin_double;
    using boost::spirit::qi::big_bin_double;
    using boost::spirit::qi::little_bin_double;

    boost::uint8_t uc;
    boost::uint16_t us;
    boost::uint32_t ui;
#ifdef BOOST_HAS_LONG_LONG
    boost::uint64_t ul;
#endif
    float f;
    double d;

    {   // test native endian binaries
#ifdef BOOST_LITTLE_ENDIAN
        BOOST_TEST(test_attr("\x01", byte_, uc) && uc == 0x01);
        BOOST_TEST(test_attr("\x01\x02", word, us) && us == 0x0201);
        BOOST_TEST(test_attr("\x01\x02\x03\x04", dword, ui) && ui == 0x04030201);
#ifdef BOOST_HAS_LONG_LONG
        BOOST_TEST(test_attr("\x01\x02\x03\x04\x05\x06\x07\x08", qword, ul) &&
            ul == 0x0807060504030201LL);
#endif
        BOOST_TEST(binary_test_attr("\x00\x00\x80\x3f", 4, bin_float, f) &&
            f == 1.0f);
        BOOST_TEST(binary_test_attr("\x00\x00\x00\x00\x00\x00\xf0\x3f",
            8, bin_double, d) && f == 1.0);
#else
        BOOST_TEST(test_attr("\x01", byte_, uc) && uc == 0x01);
        BOOST_TEST(test_attr("\x01\x02", word, us) && us ==  0x0102);
        BOOST_TEST(test_attr("\x01\x02\x03\x04", dword, ui) && ui == 0x01020304);
#ifdef BOOST_HAS_LONG_LONG
        BOOST_TEST(test_attr("\x01\x02\x03\x04\x05\x06\x07\x08", qword, ul) &&
            ul == 0x0102030405060708LL);
#endif
        BOOST_TEST(binary_test_attr("\x3f\x80\x00\x00", 4, bin_float, f) &&
            f == 1.0f);
        BOOST_TEST(binary_test_attr("\x3f\xf0\x00\x00\x00\x00\x00\x00",
            8, bin_double, d) && f == 1.0);
#endif
    }

    {   // test native endian binaries
#ifdef BOOST_LITTLE_ENDIAN
        BOOST_TEST(test("\x01", byte_(0x01)));
        BOOST_TEST(test("\x01\x02", word(0x0201)));
        BOOST_TEST(test("\x01\x02\x03\x04", dword(0x04030201)));
#ifdef BOOST_HAS_LONG_LONG
        BOOST_TEST(test("\x01\x02\x03\x04\x05\x06\x07\x08",
            qword(0x0807060504030201LL)));
#endif
        BOOST_TEST(binary_test("\x00\x00\x80\x3f", 4, bin_float(1.0f)));
        BOOST_TEST(binary_test("\x00\x00\x00\x00\x00\x00\xf0\x3f", 8,
            bin_double(1.0)));
#else
        BOOST_TEST(test("\x01", byte_(0x01)));
        BOOST_TEST(test("\x01\x02", word(0x0102)));
        BOOST_TEST(test("\x01\x02\x03\x04", dword(0x01020304)));
#ifdef BOOST_HAS_LONG_LONG
        BOOST_TEST(test("\x01\x02\x03\x04\x05\x06\x07\x08",
            qword(0x0102030405060708LL)));
#endif
        BOOST_TEST(binary_test("\x3f\x80\x00\x00", 4, bin_float(1.0f)));
        BOOST_TEST(binary_test("\x3f\x80\x00\x00\x00\x00\x00\x00", 8,
            bin_double(1.0)));
#endif
    }

    {   // test big endian binaries
        BOOST_TEST(test_attr("\x01\x02", big_word, us) && us == 0x0102);
        BOOST_TEST(test_attr("\x01\x02\x03\x04", big_dword, ui) && ui == 0x01020304);
#ifdef BOOST_HAS_LONG_LONG
        BOOST_TEST(test_attr("\x01\x02\x03\x04\x05\x06\x07\x08", big_qword, ul)
            && ul == 0x0102030405060708LL);
#endif
        BOOST_TEST(binary_test_attr("\x3f\x80\x00\x00", 4, big_bin_float, f) &&
            f == 1.0f);
        BOOST_TEST(binary_test_attr("\x3f\xf0\x00\x00\x00\x00\x00\x00",
            8, big_bin_double, d) && f == 1.0);
//.........这里部分代码省略.........
开发者ID:0xDEC0DE8,项目名称:mcsema,代码行数:101,代码来源:binary.cpp



注:本文中的spirit_test类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ sstring_t类代码示例发布时间:2022-05-31
下一篇:
C++ spinlock类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap