23570d232f0b — Duncan Ross Palmer 1 year, 2 months ago
Handle parsing of all flags correctly
2 files changed, 49 insertions(+), 7 deletions(-)

M bin/raw2c
M t/raw2c.pl
M bin/raw2c +17 -4
@@ 45,6 45,7 @@ sub new {
 		header => '',
 		inputFileName => '',
 		outputFileName => '',
+		recurse => 0,
 	}, $class);
 }
 

          
@@ 72,6 73,18 @@ sub symbolName {
 	return $self->{symbolName};
 }
 
+sub nullTerminator {
+	my ($self, @args) = @_;
+	($self->{nulllTerminator}) = @args if (scalar(@args));
+	return $self->{nulllTerminator};
+}
+
+sub recurse {
+	my ($self, @args) = @_;
+	($self->{recurse}) = @args if (scalar(@args));
+	return $self->{recurse};
+}
+
 package OptionsParser;
 use strict;
 use warnings;

          
@@ 102,10 115,10 @@ sub parse {
 		my $arg = $argumentVector->[$i];
 		if ($arg eq '-q') {
 			$options->quiet(1);
-#		} else if (compare(argumentVector[i], "-n")) {
-#			options.null_terminator = 1;
-#		} else if (compare(argumentVector[i], "-r")) {
-#			options.recurse = 1;
+		} elsif ($arg eq '-n') {
+			$options->nullTerminator(1);
+		} elsif ($arg eq '-r') {
+			$options->recurse(1);
 #		} else if (compareN(argumentVector[i], "--symbol", 8)) {
 #			char *pointer = argumentVector[i];
 #			pointer += 8; /* Move along to symbol name */

          
M t/raw2c.pl +32 -3
@@ 68,12 68,41 @@ sub testRandom {
 
 sub testParse {
 	my ($self) = @_;
-	plan tests => 1;
+	my $options;
+
+	plan tests => 3;
 
 	$self->sut(OptionsParser->new());
 
-	my $options = $self->sut->parse(['-q', 'input.bin', 'output.c']);
-	ok($options->quiet, 'quiet flag is set with -q');
+	subtest quiet => sub {
+		plan tests => 2;
+
+		$options = $self->sut->parse(['-q', 'input.bin', 'output.c']);
+		ok($options->quiet, 'quiet flag is set with -q');
+
+		$options = $self->sut->parse(['input.bin', 'output.c']);
+		ok(!$options->quiet, 'quiet flag is *NOT* set without -q');
+	};
+
+	subtest nullTerminator => sub {
+		plan tests => 2;
+
+		$options = $self->sut->parse(['-n', 'input.bin', 'output.c']);
+		ok($options->nullTerminator, 'null terminator flag is set with -n');
+
+		$options = $self->sut->parse(['input.bin', 'output.c']);
+		ok(!$options->nullTerminator, 'null terminator flag is *NOT* set without -n');
+	};
+
+	subtest recurse => sub {
+		plan tests => 2;
+
+		$options = $self->sut->parse(['-r', 'input.bin', 'output.c']);
+		ok($options->recurse, 'recurse flag is set with -r');
+
+		$options = $self->sut->parse(['input.bin', 'output.c']);
+		ok(!$options->recurse, 'recurse flag is *NOT* set without -r');
+	};
 
 	return EXIT_SUCCESS;
 }