Skip to content

Commit

Permalink
Add tests for #70
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaswerkmeister committed Nov 22, 2014
1 parent cfd24e4 commit 95669c1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,26 @@ shared CompilationUnit completeCompilationUnit
elseCaseClause = ElseCaseClause(Block([]));
};
},
SwitchCaseElse {
clause = SwitchClause(SpecifiedVariable {
name = LIdentifier("switchVariable");
specifier = Specifier(BaseExpression(MemberNameWithTypeArguments(LIdentifier("switchVariableExpression"))));
type = ValueModifier();
});
cases = SwitchCases {
caseClauses = [
CaseClause {
caseItem = MatchCase([IntegerLiteral("0")]);
block = Block([]);
},
CaseClause {
caseItem = IsCase(BaseType(TypeNameWithTypeArguments(UIdentifier("String"))));
block = Block([]);
}
];
elseCaseClause = ElseCaseClause(Block([]));
};
},
DynamicBlock(Block([])),
ValueDefinition {
name = LIdentifier("subscripts");
Expand Down
11 changes: 9 additions & 2 deletions source/test/ceylon/ast/redhat/SwitchClause.ceylon
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import ceylon.ast.core {
Expression,
LIdentifier,
SpecifiedVariable,
Specifier,
SwitchClause
}
import ceylon.ast.redhat {
Expand All @@ -15,13 +18,17 @@ import com.redhat.ceylon.compiler.typechecker.tree {

shared object switchClause satisfies ConcreteTest<SwitchClause,JSwitchClause> {

String->SwitchClause construct(String->Expression expression)
String->SwitchClause construct(String->Expression|SpecifiedVariable expression)
=> "switch (``expression.key``)"->SwitchClause(expression.item);

shared String->SwitchClause switchIClause = construct(baseExpression.iExpression);
shared String->SwitchClause switchVarIClause = construct("var = i"->SpecifiedVariable {
name = LIdentifier("var");
specifier = Specifier(baseExpression.iExpression.item);
});

compile = compileSwitchClause;
fromCeylon = RedHatTransformer.transformSwitchClause;
toCeylon = switchClauseToCeylon;
codes = [switchIClause];
codes = [switchIClause, switchVarIClause];
}

0 comments on commit 95669c1

Please sign in to comment.