-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from stdout-se/10-quotes-fix
Fix double quotation marks causing error
- Loading branch information
Showing
3 changed files
with
139 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
classdef TokenizeTests < matlab.unittest.TestCase | ||
%TOKENIZETESTS Tests for tokenize_code | ||
|
||
methods(Test) | ||
function testDoubleQuote(obj) | ||
%TESTDOUBLEQUOTE Tests a double quoted string | ||
|
||
% Input data for the test | ||
input_str = '"test"'; % String: "test" | ||
|
||
% Construct expected output for comparison | ||
expected = Token('string', input_str, 1, 1); | ||
|
||
% Get actual output | ||
actual = tokenize_code(input_str); | ||
|
||
% Compare actual output with expected output | ||
obj.verifyEqual(actual, expected); | ||
end | ||
|
||
function testSoloDoubleQuote(obj) | ||
%TESTSOLODOUBLEQUOTE Tests a string with only a double quoted | ||
|
||
% Input data for the test | ||
input_str = 'output = "test"'; % String: output = 'test' | ||
|
||
% Construct expected output for comparison | ||
expected(1) = Token('identifier', 'output', 1, 1); | ||
expected(2) = Token('space', ' ', 1, 7); | ||
expected(3) = Token('punctuation', '=', 1, 8); | ||
expected(4) = Token('space', ' ', 1, 9); | ||
expected(5) = Token('string', '"test"', 1, 10); | ||
|
||
% Get actual output | ||
actual = tokenize_code(input_str); | ||
|
||
% Compare actual output with expected output | ||
obj.verifyEqual(actual, expected); | ||
end | ||
|
||
function testNestedQuote(obj) | ||
%TESTNESTEDQUOTE Tests a double quote inside single quote | ||
|
||
% Input data for the test | ||
input_str = '"let''s go"'; % String: "let's go" | ||
|
||
% Construct expected output for comparison | ||
expected = Token('string', input_str, 1, 1); | ||
|
||
% Get actual output | ||
actual = tokenize_code(input_str); | ||
|
||
% Compare actual output with expected output | ||
obj.verifyEqual(actual, expected); | ||
end | ||
|
||
function testNestedQuote2(obj) | ||
%TESTNESTEDQUOTE2 Tests a double quote inside single quote | ||
|
||
% Input data for the test | ||
input_str = '''He said, "hi"'''; % String: 'He said, "hi"' | ||
|
||
% Construct expected output for comparison | ||
expected = Token('string', input_str, 1, 1); | ||
|
||
% Get actual output | ||
actual = tokenize_code(input_str); | ||
|
||
% Compare actual output with expected output | ||
obj.verifyEqual(actual, expected); | ||
end | ||
end | ||
end |
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,28 @@ | ||
function run_unittests() | ||
%RUN_UNITTESTS Runs all unit tests | ||
|
||
import matlab.unittest.TestSuite | ||
import matlab.unittest.TestRunner | ||
|
||
try | ||
% Create a test suite | ||
suite = ... | ||
TestSuite.fromPackage('UnitTest', ... | ||
'IncludingSubpackages', true); | ||
|
||
% Run all tests | ||
runner = TestRunner.withTextOutput; | ||
result = runner.run(suite); | ||
|
||
% Display results | ||
disp(table(result)); | ||
disp(result); | ||
|
||
% Throw an error if any test failed | ||
if sum([result(:).Failed]) + sum([result(:).Incomplete]) > 0 | ||
error('There are failing unittests!') | ||
end | ||
catch err | ||
disp(err.getReport) | ||
end | ||
end |
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