Skip to content

Commit

Permalink
add error diagnostic for 2-arg form of [switch], and fix bug
Browse files Browse the repository at this point in the history
(weren't actually treating the 2nd arg as a list)
  • Loading branch information
coke committed Jul 4, 2010
1 parent 88c63f7 commit 09e46d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/Partcl/commands/main.pm
Expand Up @@ -640,8 +640,10 @@ our sub switch(*@args) {

my $string := @args.shift();
if +@args == 1 {
# list form; expand the list.
@args := @args.getList();
# list form; expand the list.
@args := @args[0].getList();
error('wrong # args: should be "switch ?switches? string {pattern body ... ?default body?}"')
unless +@args;
}
if +@args % 2 == 1 {
error('extra switch pattern with no body');
Expand Down
22 changes: 11 additions & 11 deletions t/cmd_switch.t
Expand Up @@ -17,7 +17,7 @@ eval_is {switch -monkey a} \

eval_is {switch a { }} \
{wrong # args: should be "switch ?switches? string {pattern body ... ?default body?}"} \
{empty body} {TODO NQPRX}
{empty body}

eval_is {
set q 1
Expand Down Expand Up @@ -57,7 +57,7 @@ eval_is {
ab { set q 2 }
}
set q
} 2 {implied exact, single choice in list} {TODO NQPRX}
} 2 {implied exact, single choice in list}

eval_is {
set q 1
Expand All @@ -68,7 +68,7 @@ eval_is {
ba { set q 5 }
}
set q
} 4 {implied exact, no globbing} {TODO NQPRX}
} 4 {implied exact, no globbing}

eval_is {
set q 1
Expand All @@ -80,7 +80,7 @@ eval_is {
default { set q 6 }
}
set q
} 6 {implied exact, default} {TODO NQPRX}
} 6 {implied exact, default}

eval_is {
set q 1
Expand All @@ -92,7 +92,7 @@ eval_is {
default { set q 6 }
}
set q
} 4 {implied exact, match before default} {TODO NQPRX}
} 4 {implied exact, match before default}

eval_is {
set q 1
Expand All @@ -103,7 +103,7 @@ eval_is {
ba { set q 5 }
}
set q
} 1 {implied exact, no match, no default} {TODO NQPRX}
} 1 {implied exact, no match, no default}

eval_is {
set q 1
Expand All @@ -113,15 +113,15 @@ eval_is {
ba { set q 4 }
}
set q
} 3 {implied exact, choices in list} {TODO NQPRX}
} 3 {implied exact, choices in list}

eval_is {
switch -nocase C {
c {set ok 1}
default {set ok 0}
}
set ok
} 1 {implied exact, nocase subject} {TODO NQPRX}
} 1 {implied exact, nocase subject}

eval_is {
switch a {
Expand Down Expand Up @@ -153,7 +153,7 @@ eval_is {
ab { set q 4 }
}
set q
} 3 {-glob, three choices} {TODO NQPRX}
} 3 {-glob, three choices}

eval_is {
set q 1
Expand All @@ -163,7 +163,7 @@ eval_is {
*a { set q 3 }
}
set q
} 1 {-glob, no match, no default} {TODO NQPRX}
} 1 {-glob, no match, no default}

eval_is {
set q 1
Expand All @@ -174,7 +174,7 @@ eval_is {
default { set q 5 }
}
set q
} 5 {-glob, no match, default} {TODO NQPRX}
} 5 {-glob, no match, default}

eval_is {switch -glob a {a 1 b}} \
{extra switch pattern with no body} \
Expand Down

0 comments on commit 09e46d1

Please sign in to comment.