forked from ebranlard/matlab2python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update of tests, using test directory
- Loading branch information
Showing
14 changed files
with
119 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import numpy as np | ||
import unittest | ||
|
||
from matlabparser.parser import * | ||
|
||
# --------------------------------------------------------------------------------} | ||
# --- | ||
# --------------------------------------------------------------------------------{ | ||
class TestParser(unittest.TestCase): | ||
|
||
def test_names(self): | ||
#self.assertEqual(extract_function_name('function y = f(a,b)'),'f')) | ||
self.assertEqual(parse_function_def('function y = f(a,b)'),('f',['y'],['a','b'])) | ||
self.assertEqual(parse_function_def('function f; '),('f',[],[])) | ||
self.assertEqual(parse_function_def('function f ; '),('f',[],[])) | ||
self.assertEqual(parse_function_def('function foo '),('foo',[],[])) | ||
self.assertEqual(parse_function_def('function foo() '),('foo',[],[])) | ||
self.assertEqual(parse_function_def('function foo ( ); '),('foo',[],[])) | ||
self.assertEqual(parse_function_def('function [a b] = f(c)'),('f',['a','b'],['c'])) | ||
self.assertEqual(parse_function_def('function [a,b] = f(c)'),('f',['a','b'],['c'])) | ||
self.assertEqual(parse_class_def('classdef y<h') ,('y',['h'])) | ||
self.assertEqual(parse_class_def('classdef y < h ;'),('y',['h'])) | ||
self.assertEqual(parse_class_def('classdef y') ,('y',[])) | ||
self.assertEqual(parse_class_def('classdef y;') ,('y',[])) | ||
self.assertRaises(Exception,parse_class_def,'classdef') | ||
|
||
def test_comment(self): | ||
self.assertEqual(separate_comment(''),('','')) | ||
self.assertEqual(separate_comment('%%'),('','%%')) | ||
self.assertEqual(separate_comment(' %%'),(' ','%%')) | ||
self.assertEqual(separate_comment('%hi'),('','%hi')) | ||
self.assertEqual(separate_comment("""s='%' %com"""),("""s='%' """,'%com')) | ||
self.assertEqual(separate_comment("""A=B' %com"""),("""A=B' """,'%com')) | ||
self.assertEqual(separate_comment("""s='%';A=B' %com"""),("""s='%';A=B' """,'%com')) | ||
self.assertEqual(separate_comment("""s='%';A=B' %com '%com2"""),("""s='%';A=B' ""","""%com '%com2""")) | ||
|
||
def test_string(self): | ||
self.assertEqual(find_strings("""""") ,([],False)) | ||
self.assertEqual(find_strings("""AAAA""") ,([],False)) | ||
self.assertEqual(find_strings("""'""") ,([(0,'')],True)) | ||
self.assertEqual(find_strings("""''""") ,([(0,'')],False)) | ||
self.assertEqual(find_strings(""" 'a'"""),([(3,'a')],False)) | ||
self.assertEqual(find_strings("""x='a' """),([(2,'a')],False)) | ||
self.assertEqual(find_strings("""x= 'a'"""),([(3,'a')],False)) | ||
self.assertEqual(find_strings(""" x=A' """),([],False)) | ||
self.assertEqual(find_strings(""" [0]' """),([],False)) | ||
self.assertEqual(find_strings(""" x(:)' """),([],False)) | ||
self.assertEqual(find_strings(""" {0}' """),([],False)) | ||
self.assertEqual(find_strings(""" 0.' """),([],False)) | ||
self.assertEqual(find_strings(""" A'' """),([],False)) | ||
self.assertEqual(find_strings(""" (A')' """),([],False)) | ||
self.assertEqual(find_strings(""" [0] ' """),([],False)) | ||
self.assertEqual(find_strings(""" [a 'bbb'] """),([(4,'bbb')],False)) | ||
self.assertEqual(find_strings("""f('it''s') """),([(2,"""it''s""")],False)) | ||
self.assertEqual(find_strings("""x='a';y='b'"""),([(2,'a'),(8,'b')],False)) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import numpy as np | ||
import unittest | ||
|
||
from matlabparser.parsing_tools import * | ||
# --------------------------------------------------------------------------------} | ||
# --- | ||
# --------------------------------------------------------------------------------{ | ||
class TestParsingTools(unittest.TestCase): | ||
|
||
def assertEqual(self, first, second, msg=None): | ||
#print('\n>',first,'<',' >',second,'<') | ||
super(TestParsingTools, self).assertEqual(first, second, msg) | ||
|
||
def test_strings(self): | ||
self.assertEqual(string_contains_charset('g' ,r'[a-z]'),True) | ||
self.assertEqual(string_contains_charset('09' ,r'[a-z]'),False) | ||
self.assertEqual(string_contains_charset('0g9',r'[a-z]'),True) | ||
self.assertEqual(previous_nonspace_pos ('01 8',8),1 ) | ||
self.assertEqual(previous_nonspace_pos (' 8',8),-1) | ||
self.assertEqual(previous_nonspace_char('01 8',8),'1') | ||
self.assertEqual(previous_nonspace_char(' 8',8),'') | ||
|
||
def test_quotes(self): | ||
# self.assertEqual(is_in_quotes("""0 '345' 7 """ ,4) ,True) | ||
# self.assertEqual(is_in_quotes("""01'345' 7 """ ,2) ,False) | ||
#self.assertEqual(is_in_quotes("""01'345' 7 """ ,6) ,False) | ||
self.assertEqual(replace_inquotes("""''""" ,'X') ,'XX') | ||
self.assertEqual(replace_inquotes("""0'23'5""" ,'X') ,'0XXXX5') | ||
self.assertEqual(replace_inquotes("""0'2"'5""" ,'X') ,'0XXXX5') | ||
self.assertEqual(replace_inquotes("""0"23"5""" ,'X') ,'0XXXX5') | ||
self.assertEqual(replace_inquotes("""0'2''5'7""" ,'X') ,'0XXXXXX7') | ||
self.assertEqual(replace_inquotes("""0'23""" ,'X') ,'0XXX') | ||
self.assertEqual(replace_inquotes("""0"23""" ,'X') ,'0XXX') | ||
self.assertEqual(extract_quotedstring("""''""") ,'') | ||
self.assertEqual(extract_quotedstring("""'a'""") ,'a') | ||
self.assertEqual(extract_quotedstring("""'a'b""") ,'a') | ||
self.assertEqual(extract_quotedstring("""'a""") ,'a') | ||
self.assertEqual(extract_quotedstring("""'a''a'""") ,'a\'\'a') | ||
self.assertEqual(extract_quotedstring("""'a"a'""") ,'a"a') | ||
self.assertEqual(extract_quotedstring('""') ,'') | ||
#print('>>>>>>>>>>>>>>') | ||
#print('>>>>>>>>>>>>>>') | ||
#print('>>>>>>>>>>>>>>') | ||
#print('>>>>>>>>>>>>>>') | ||
#self.assertEqual(separate_comment('s='i'),(' ',' ')) |