-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLiteralTreeTest.java
More file actions
64 lines (55 loc) · 2.18 KB
/
LiteralTreeTest.java
File metadata and controls
64 lines (55 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* SonarSource Scala
* Copyright (C) 2018-2025 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Sonar Source-Available License for more details.
*
* You should have received a copy of the Sonar Source-Available License
* along with this program; if not, see https://sonarsource.com/license/ssal/
*/
package org.sonarsource.scala.converter;
import org.junit.jupiter.api.Test;
import org.sonarsource.slang.api.LiteralTree;
import org.sonarsource.slang.api.Tree;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonarsource.slang.testing.TreeAssert.assertTree;
class LiteralTreeTest extends AbstractScalaConverterTest {
@Test
void string_literal() {
assertTree(scalaStatement("\"Hello\"")).isEquivalentTo(slangStatement("\"Hello\";"));
}
@Test
void string_with_interpolation() {
Tree tree = scalaStatement("raw\"abc\"");
assertTree(tree).isNotInstanceOf(LiteralTree.class);
assertThat(tree.descendants()
.filter(LiteralTree.class::isInstance)
.map(LiteralTree.class::cast)
.map(LiteralTree::value)).containsExactly("\"abc\"");
//Test that string interpolation with variable are not mapped to LiteralTree
Tree interpolationTree = scalaStatement("s\"abc $x \"");
assertThat(interpolationTree.descendants().filter(LiteralTree.class::isInstance)).isEmpty();
}
@Test
void int_literal() {
assertTree(scalaStatement("42")).isEquivalentTo(slangStatement("42;"));
}
@Test
void non_int_numeric_literals() {
assertTree(scalaStatement("42.1")).isLiteral("42.1");
assertTree(scalaStatement("42.1f")).isLiteral("42.1f");
assertTree(scalaStatement("42.1d")).isLiteral("42.1d");
}
@Test
void boolean_literals() {
assertTree(scalaStatement("true")).isLiteral("true");
assertTree(scalaStatement("false")).isLiteral("false");
}
}