Skip to content

Commit

Permalink
Add guard default tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Horcrux7 committed Sep 30, 2018
1 parent 300d796 commit 67729a9
Show file tree
Hide file tree
Showing 2 changed files with 325 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
guard-default-basic-1-1 {
case: 1;
}
guard-default-basic-1-2 {
default: 2;
}
guard-default-basic-2-0 {
default: 0;
}
guard-default-basic-2-2 {
case: 2;
}
guard-default-basic-3-0 {
default: 0;
}
guard-default-basic-3-2 {
case: 2;
}
guard-default-basic-3-3 {
case: 3;
}
guard-default-definition-order-0 {
default: 0;
}
guard-default-definition-order-2 {
case: 2;
case: 3;
}
guard-default-out-of-guard-0 {
case-0: default();
case-1: 1;
default: 2;
case-2: default();
}
guard-default-out-of-guard-1 {
default: default();
}
guard-default-out-of-guard-2 {
default: default();
}
guard-default-expr-not-1 {
case: 1;
default: 1;
}
guard-default-expr-not-2 {
default: 2;
}
guard-default-expr-eq-true {
case: true;
}
guard-default-expr-eq-false {
case: false;
default: false;
}
guard-default-expr-or-1 {
case: 1;
}
guard-default-expr-or-2 {
case: 2;
default: 2;
}
guard-default-expr-or-3 {
default: 3;
}
guard-default-expr-and-1 {
case: 1;
}
guard-default-expr-and-2 {
case: 2;
}
guard-default-expr-and-3 {
default: 3;
}
guard-default-expr-always-1 {
case: 1;
default: 1;
}
guard-default-expr-always-2 {
default: 2;
}
guard-default-expr-never-1 {
case: 1;
}
guard-default-multi-1-0 {
case: 0;
}
guard-default-multi-1-1 {
default-1: 1;
}
guard-default-multi-2-1 {
default-1: no;
}
guard-default-multi-2-2 {
default-2: no;
}
guard-default-multi-2-3 {
default-3: 3;
}
guard-default-multi-3-blue {
case-2: darkblue;
}
guard-default-multi-3-green {
default-color: green;
}
guard-default-multi-3-foo {
case-1: I am 'foo';
}
guard-default-multi-3-baz {
default-string: I am 'baz';
}
guard-default-multi-4 {
always: 1;
always: 2;
case: 2;
}
guard-default-not-ambiguos-2 {
case: 1;
not-default: 2;
}
guard-default-not-ambiguos-3 {
case: 1;
not-default-1: 2;
not-default-2: 2;
}
guard-default-scopes-3 {
3: when default;
}
guard-default-scopes-1 {
1: no condition;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@

// basics:

guard-default-basic-1 {
.m(1) {case: 1}
.m(@x) when (default()) {default: @x}

&-1 {.m(1)}
&-2 {.m(2)}
}

guard-default-basic-2 {
.m(1) {case: 1}
.m(2) {case: 2}
.m(3) {case: 3}
.m(@x) when (default()) {default: @x}

&-0 {.m(0)}
&-2 {.m(2)}
}

guard-default-basic-3 {
.m(@x) when (@x = 1) {case: 1}
.m(2) {case: 2}
.m(@x) when (@x = 3) {case: 3}
.m(@x) when (default()) {default: @x}

&-0 {.m(0)}
&-2 {.m(2)}
&-3 {.m(3)}
}

guard-default-definition-order {
.m(@x) when (default()) {default: @x}
.m(@x) when (@x = 1) {case: 1}
.m(2) {case: 2}
.m(@x) when (@x = 3) {case: 3}

&-0 {.m(0)}
&-2 {.m(2)}
&-2 {.m(3)}
}

// out of guard:

guard-default-out-of-guard {
.m(1) {case-1: 1}
.m(@x: default()) when (default()) {default: @x}

&-0 {
case-0: default();
.m(1);
.m(2);
case-2: default();
}
&-1 {.m(default())}
&-2 {.m()}
}

// expressions:

guard-default-expr-not {
.m(1) {case: 1}
.m(@x) when not(default()) {default: @x}

&-1 {.m(1)}
&-2 {.m(2)}
}

guard-default-expr-eq {
.m(@x) when (@x = true) {case: @x}
.m(@x) when (@x = false) {case: @x}
.m(@x) when (@x = default()) {default: @x}

&-true {.m(true)}
&-false {.m(false)}
}

guard-default-expr-or {
.m(1) {case: 1}
.m(2) {case: 2}
.m(@x) when (default()), (@x = 2) {default: @x}

&-1 {.m(1)}
&-2 {.m(2)}
&-3 {.m(3)}
}

guard-default-expr-and {
.m(1) {case: 1}
.m(2) {case: 2}
.m(@x) when (default()) and (@x = 3) {default: @x}

&-1 {.m(1)}
&-2 {.m(2)}
&-3 {.m(3)}
&-4 {.m(4)}
}

guard-default-expr-always {
.m(1) {case: 1}
.m(@x) when (default()), not(default()) {default: @x} // always match

&-1 {.m(1)}
&-2 {.m(2)}
}

guard-default-expr-never {
.m(1) {case: 1}
.m(@x) when (default()) and not(default()) {default: @x} // never match

&-1 {.m(1)}
&-2 {.m(2)}
}


// not conflicting multiple default() uses:

guard-default-multi-1 {
.m(0) {case: 0}
.m(@x) when (default()) {default-1: @x}
.m(2) when (default()) {default-2: @x}

&-0 {.m(0)}
&-1 {.m(1)}
}

guard-default-multi-2 {
.m(1, @x) when (default()) {default-1: @x}
.m(2, @x) when (default()) {default-2: @x}
.m(@x, yes) when (default()) {default-3: @x}

&-1 {.m(1, no)}
&-2 {.m(2, no)}
&-3 {.m(3, yes)}
}

guard-default-multi-3 {
.m(red) {case-1: darkred}
.m(blue) {case-2: darkblue}
.m(@x) when (iscolor(@x)) and (default()) {default-color: @x}
.m('foo') {case-1: I am 'foo'}
.m('bar') {case-2: I am 'bar'}
.m(@x) when (isstring(@x)) and (default()) {default-string: I am @x}

&-blue {.m(blue)}
&-green {.m(green)}
&-foo {.m('foo')}
&-baz {.m('baz')}
}

guard-default-multi-4 {
.m(@x) when (default()), not(default()) {always: @x}
.m(@x) when (default()) and not(default()) {never: @x}
.m(2) {case: 2}

.m(1);
.m(2);
}

guard-default-not-ambiguos-2 {
.m(@x) {case: 1}
.m(@x) when (default()) {default: @x}
.m(@x) when not(default()) {not-default: @x}

.m(2);
}

guard-default-not-ambiguos-3 {
.m(@x) {case: 1}
.m(@x) when not(default()) {not-default-1: @x}
.m(@x) when not(default()) {not-default-2: @x}

.m(2);
}

// default & scope

guard-default-scopes {
.s1() {.m(@v) {1: no condition}}
.s2() {.m(@v) when (@v) {2: when true}}
.s3() {.m(@v) when (default()) {3: when default}}

&-3 {
.s2();
.s3();
.m(false);
}

&-1 {
.s1();
.s3();
.m(false);
}
}

0 comments on commit 67729a9

Please sign in to comment.