Permalink
Browse files

* command.erl

  New clause for parsing open port type command

* command.hrl
  New record type #open{}

* command_tests.erl
  New test for open command
  • Loading branch information...
1 parent 167aa41 commit d26c27696d0f6cfd5c543c5a154e82a109255428 Gianfranco Alongi committed Mar 9, 2012
Showing with 18 additions and 1 deletion.
  1. +7 −1 Two/Solution/src/command.erl
  2. +4 −0 Two/Solution/src/command.hrl
  3. +7 −0 Two/Solution/test/command_tests.erl
@@ -17,7 +17,13 @@ parse("bind "++Rest) ->
parse("unbind "++Type) ->
#binding{type = unbind,
- arguments = [{type,Type}]}.
+ arguments = [{type,Type}]};
+
+parse("open "++Rest) ->
+ [Port,Type] = string:tokens(Rest," "),
+ #open{port = list_to_integer(Port),
+ type = Type}.
+
@@ -1,3 +1,7 @@
-record(binding,{type :: list | bind | unbind,
arguments :: [{atom(),string()}]
}).
+
+-record(open,{port :: non_neg_integer(),
+ type :: string()
+ }).
@@ -22,5 +22,12 @@ unbind_test() ->
?assertMatch(#binding{type = unbind,
arguments = [{type,"testtype"}]},
command:parse(Command)).
+
+open_test() ->
+ Command = "open 1234 testtype",
+ ?assertMatch(#open{port = 1234,
+ type = "testtype"},
+ command:parse(Command)).
+

0 comments on commit d26c276

Please sign in to comment.