def test_process_oneline_pattern(self): source = os.path.join(SAMPLES_DIR, 'example5', 'slides.md') m = macro.IncludeMacro(self.logtest) content, classes = m.process('<p>.coden: src/day.c /.+wednesday/</p>', source) self.assertTrue(re.search(r'"lineno"> *1<.*wednesday', content)) self.assertFalse(re.search(r'"lineno"> *2<', content))
def test_process_whole_file(self): source = os.path.join(SAMPLES_DIR, 'example5', 'slides.md') m = macro.IncludeMacro(self.logtest) content, classes = m.process('<p>.coden: src/day.c</p>', source) self.assertTrue(re.search(r'"lineno"> *1<.*stdio\.h', content)) self.assertTrue(re.search(r'"lineno"> *22<.*>}<', content)) self.assertFalse(re.search(r'"lineno"> *23<', content))
def test_process_offset_fancy(self): source = os.path.join(SAMPLES_DIR, 'example5', 'slides.md') m = macro.IncludeMacro(self.logtest) content, classes = m.process( '<p>.coden: src/day.c /static.const.char.+day/+2 /}/-</p>', source) self.assertTrue(re.search(r'"lineno"> *1<.*monday', content)) self.assertTrue(re.search(r'"lineno"> *7<.*sunday', content)) self.assertFalse(re.search(r'"lineno"> *8<', content))
def test_process_multiline_num_positive(self): source = os.path.join(SAMPLES_DIR, 'example5', 'slides.md') m = macro.IncludeMacro(self.logtest) content, classes = m.process('<p>.coden: src/day.c 8 10</p>', source) self.assertTrue(re.search(r'"lineno"> *1<.*wednesday', content)) self.assertTrue(re.search(r'"lineno"> *2<.*thursday', content)) self.assertTrue(re.search(r'"lineno"> *3<.*friday', content)) self.assertFalse(re.search(r'"lineno"> *4<', content))
def test_process_option_expandtabs_per_macro(self): source = os.path.join(SAMPLES_DIR, 'example5', 'slides.md') m = macro.IncludeMacro(self.logtest) ts = 2 content, classes = m.process( '<p>.coden' + str(ts) + ': src/day.c /.+wednesday/</p>', source) self.assertTrue( re.search(r'"lineno"> *1<.*>\s?[ ]{' + str(ts) + '}<.*wednesday', content))
def test_process_offset_errors(self): source = os.path.join(SAMPLES_DIR, 'example5', 'slides.md') m = macro.IncludeMacro(self.logtest) self.assertRaises(WarningMessage, m.process, '<p>.code: src/day.c /main/+8</p>', source) self.assertRaises(WarningMessage, m.process, '<p>.code: src/day.c /main/-15</p>', source) self.assertRaises(WarningMessage, m.process, '<p>.code: src/day.c /main/+4 /}/-4</p>', source)
def test_process_offset_simple(self): source = os.path.join(SAMPLES_DIR, 'example5', 'slides.md') m = macro.IncludeMacro(self.logtest) content, classes = m.process( '<p>.coden: src/day.c /main\(.+\)/- /}/</p>', source) self.assertTrue(re.search(r'"lineno"> *1<.*int', content)) self.assertTrue(re.search(r'"lineno"> *2<.*main', content)) self.assertTrue(re.search(r'"lineno"> *9<.*}', content)) self.assertFalse(re.search(r'"lineno"> *10<', content))
def test_process_multiline_errors(self): source = os.path.join(SAMPLES_DIR, 'example5', 'slides.md') m = macro.IncludeMacro(self.logtest) self.assertRaises(WarningMessage, m.process, '<p>.code: src/day.c /foo/ /bar/</p>', source) self.assertRaises(WarningMessage, m.process, '<p>.code: src/day.c 11 7</p>', source) self.assertRaises(WarningMessage, m.process, '<p>.code: src/day.c -5 -10</p>', source)
def test_process_option_includepath(self): source = os.path.join(SAMPLES_DIR, 'example5', 'slides.md') m = macro.IncludeMacro(self.logtest) includepath_old = m.options['includepath'] m.options['includepath'] = '.' self.assertRaises(WarningMessage, m.process, '<p>.coden: day.c /.+wednesday/</p>', source) content, classes = m.process('<p>.coden: src/day.c /.+wednesday/</p>', source) self.assertTrue(re.search(r'"lineno"> *1<.*wednesday', content)) m.options['includepath'] = includepath_old