blob: 03b7d2b5134d4b6d6c2850d33185461b2770c5d0 [file] [log] [blame]
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.turbine.parse;
import static com.google.common.truth.Truth.assertThat;
import com.google.common.base.Joiner;
import com.google.common.collect.Iterables;
import com.google.turbine.tree.Tree;
import com.google.turbine.tree.TurbineModifier;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class ParserTest {
// regression test: only enum constants with bodies should have ENUM_IMPL set
@Test
public void enumConstantDeclaration() {
String[] input = {
"enum E {", //
" ONE {",
" public void f() {}",
" },",
" TWO;",
"}",
};
Tree.CompUnit unit = Parser.parse(Joiner.on('\n').join(input));
Tree.TyDecl decl = Iterables.getOnlyElement(unit.decls());
assertThat(((Tree.VarDecl) decl.members().get(0)).mods())
.containsExactly(
TurbineModifier.PUBLIC,
TurbineModifier.STATIC,
TurbineModifier.ACC_ENUM,
TurbineModifier.FINAL,
TurbineModifier.ENUM_IMPL);
assertThat(((Tree.VarDecl) decl.members().get(1)).mods())
.containsExactly(
TurbineModifier.PUBLIC,
TurbineModifier.STATIC,
TurbineModifier.ACC_ENUM,
TurbineModifier.FINAL);
}
}