<s> if __name__ == '<STR_LIT:__main__>' : <EOL> import sys <EOL> from os import path <EOL> sys . path . insert ( <NUM_LIT:0> , path . abspath ( path . join ( path . dirname ( sys . argv [ <NUM_LIT:0> ] ) , '<STR_LIT:..>' ) ) ) <EOL> import unittest <EOL> import core_parsers <EOL> import string <EOL> from picoparse import partial as p <EOL> from picoparse . text import newline , whitespace_char , whitespace , whitespace1 <EOL> from picoparse . text import lexeme , quote , quoted , caseless_string , run_text_parser <EOL> from utils import TextParserTestCase <EOL> class TestTextTokenConsumers ( core_parsers . TestTokenConsumers ) : <EOL> def run_parser ( self , * args ) : <EOL> return run_text_parser ( * args ) <EOL> class TestTextManyCombinators ( core_parsers . TestManyCombinators ) : <EOL> def run_parser ( self , * args ) : <EOL> return run_text_parser ( * args ) <EOL> class TestTextSeparatorCombinators ( core_parsers . TestSeparatorCombinators ) : <EOL> def run_parser ( self , * args ) : <EOL> return run_text_parser ( * args ) <EOL> class TestTextSequencingCombinators ( core_parsers . TestSequencingCombinators ) : <EOL> def run_parser ( self , * args ) : <EOL> return run_text_parser ( * args ) <EOL> class TestTextFuture ( core_parsers . TestFuture ) : <EOL> def run_parser ( self , * args ) : <EOL> return run_text_parser ( * args ) <EOL> whitespace_strings = [ '<STR_LIT:U+0020>' , '<STR_LIT:U+0020>' , '<STR_LIT:U+0020>' , '<STR_LIT:\n>' , '<STR_LIT:\t>' , '<STR_LIT>' ] <EOL> class TestWhitespaceParsers ( TextParserTestCase ) : <EOL> def testnewline ( self ) : <EOL> self . assertNoMatch ( newline , '<STR_LIT>' ) <EOL> self . assertMatch ( newline , '<STR_LIT:\n>' , '<STR_LIT:\n>' , [ ] ) <EOL> self . assertMatch ( newline , '<STR_LIT>' , '<STR_LIT:\n>' , '<STR_LIT:\n>' ) <EOL> self . assertNoMatch ( newline , '<STR_LIT:\r\n>' ) <EOL> self . assertNoMatch ( newline , '<STR_LIT:\r>' ) <EOL> def testwhitespace_char ( self ) : <EOL> self . assertNoMatch ( whitespace_char , '<STR_LIT>' ) <EOL> for ch in string . whitespace : <EOL> self . assertMatch ( whitespace_char , ch , ch , '<STR_LIT>' ) <EOL> self . assertMatch ( whitespace_char , ch + '<STR_LIT:U+0020>' , ch , '<STR_LIT:U+0020>' ) <EOL> self . assertMatch ( whitespace_char , ch + '<STR_LIT:a>' , ch , '<STR_LIT:a>' ) <EOL> self . assertNoMatch ( whitespace_char , '<STR_LIT:a>' ) <EOL> def testwhitespace ( self ) : <EOL> self . assertMatch ( whitespace , '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT:a>' ) <EOL> for ws in whitespace_strings : <EOL> self . assertMatch ( whitespace , ws , ws , '<STR_LIT>' ) <EOL> self . assertMatch ( whitespace , ws + '<STR_LIT:a>' , ws , '<STR_LIT:a>' ) <EOL> def testwhitespace1 ( self ) : <EOL> self . assertNoMatch ( whitespace1 , '<STR_LIT>' ) <EOL> self . assertNoMatch ( whitespace1 , '<STR_LIT:a>' ) <EOL> for ws in whitespace_strings : <EOL> self . assertMatch ( whitespace1 , ws , ws , '<STR_LIT>' ) <EOL> self . assertMatch ( whitespace1 , ws + '<STR_LIT:a>' , ws , '<STR_LIT:a>' ) <EOL> class TestSimpleParsers ( TextParserTestCase ) : <EOL> def testquote ( self ) : <EOL> self . assertMatch ( quote , "<STR_LIT:'>" , "<STR_LIT:'>" , '<STR_LIT>' ) <EOL> self . assertMatch ( quote , '<STR_LIT:">' , '<STR_LIT:">' , '<STR_LIT>' ) <EOL> self . assertMatch ( quote , "<STR_LIT>" , "<STR_LIT:'>" , '<STR_LIT:a>' ) <EOL> self . assertMatch ( quote , '<STR_LIT>' , '<STR_LIT:">' , '<STR_LIT:a>' ) <EOL> self . assertNoMatch ( quote , '<STR_LIT>' ) <EOL> def testdigit ( self ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def testdigits ( self ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def testnumber ( self ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def testfloating ( self ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def testalpha ( self ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def testword ( self ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def testbuild_string ( self ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def testas_string ( self ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def testcaseless_string ( self ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> class TestLiterals ( TextParserTestCase ) : <EOL> def make_literal ( self ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def literal ( self ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def make_caseless_literal ( self ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def caseless_literal ( self ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> class TestWrappers : <EOL> def testparened ( self ) : <EOL> parened_lit = partial ( parened , make_literal ( '<STR_LIT>' ) ) <EOL> self . testwrapper ( parened_lit , "<STR_LIT:(>" , "<STR_LIT>" , "<STR_LIT:)>" ) <EOL> def testbraced ( self ) : <EOL> braced_lit = partial ( braced , make_literal ( '<STR_LIT>' ) ) <EOL> self . testwrapper ( bracketed_lit , "<STR_LIT:[>" , "<STR_LIT>" , "<STR_LIT:]>" ) <EOL> def testbraced ( self ) : <EOL> braced_lit = partial ( braced , make_literal ( '<STR_LIT>' ) ) <EOL> self . testwrapper ( bracketed_lit , "<STR_LIT:{>" , "<STR_LIT>" , "<STR_LIT:}>" ) <EOL> def testquoted ( self ) : <EOL> quoted_quote = partial ( quoted , quote ) <EOL> self . testwrapper ( quoted , "<STR_LIT:'>" , '<STR_LIT>' , "<STR_LIT:'>" ) <EOL> self . testwrapper ( quoted , '<STR_LIT:">' , '<STR_LIT>' , '<STR_LIT:">' ) <EOL> self . testwrapper ( quoted_quote , "<STR_LIT:'>" , '<STR_LIT:">' , "<STR_LIT:'>" ) <EOL> self . testwrapper ( quoted_quote , '<STR_LIT:">' , "<STR_LIT:'>" , '<STR_LIT:">' ) <EOL> self . assertNoMatch ( quoted , '<STR_LIT>' ) <EOL> self . assertNoMatch ( quoted , '<STR_LIT>' ) <EOL> self . assertNoMatch ( quoted_quote , "<STR_LIT>" ) <EOL> self . assertNoMatch ( quoted_quote , '<STR_LIT>' ) <EOL> def testlexeme ( self ) : <EOL> lex_lit = partial ( lexeme , make_literal ( '<STR_LIT>' ) ) <EOL> lex_number = partial ( lexeme , digits ) <EOL> self . assertMatch ( lex_number , '<STR_LIT:0>' , '<STR_LIT:0>' , '<STR_LIT>' ) <EOL> self . assertMatch ( lex_number , '<STR_LIT:0>' , '<STR_LIT>' , '<STR_LIT:a>' ) <EOL> self . assertMatch ( lex_lit , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertMatch ( lex_lit , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:a>' ) <EOL> for ws1 in whitespace_strings : <EOL> self . assertMatch ( lex_lit , ws1 + '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertMatch ( lex_number , '<STR_LIT>' + ws1 , <NUM_LIT> , '<STR_LIT>' ) <EOL> self . assertMatch ( lex_number , '<STR_LIT>' + ws1 + '<STR_LIT:a>' , <NUM_LIT> , '<STR_LIT:a>' ) <EOL> for ws2 in whitespace_strings : <EOL> self . assertMatch ( lex_lit , ws1 + '<STR_LIT>' + ws2 , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertMatch ( lex_number , ws1 + '<STR_LIT>' + ws2 , <NUM_LIT> , '<STR_LIT>' ) <EOL> self . assertMatch ( lex_number , ws1 + '<STR_LIT>' + ws2 + '<STR_LIT:a>' , <NUM_LIT> , '<STR_LIT:a>' ) <EOL> self . assertNoMatch ( lex_number , '<STR_LIT>' ) <EOL> self . assertNoMatch ( lex_lit , '<STR_LIT>' ) <EOL> def testwrapper ( self , parser , before , middle , after ) : <EOL> self . assertMatch ( parser , before + middle + after , middle , '<STR_LIT>' ) <EOL> self . assertNoMatch ( parser , '<STR_LIT>' ) <EOL> self . assertNoMatch ( parser , middle ) <EOL> self . assertNoMatch ( parser , before + middle ) <EOL> self . assertNoMatch ( parser , middle + after ) <EOL> self . assertNoMatch ( parser , before + after ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) <EOL> __all__ = [ cls . __name__ for name , cls in locals ( ) . items ( ) <EOL> if isinstance ( cls , type ) <EOL> and name . startswith ( '<STR_LIT>' ) ] </s>
