Skip to content

Commit

Permalink
Add test case for compilation error
Browse files Browse the repository at this point in the history
  • Loading branch information
hasathcharu committed Mar 12, 2024
1 parent a33f034 commit d5247ea
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ private Package loadPersistModelFile(String directory, String name) {
return project.currentPackage();
}

@Test(enabled = true)
public void testHasCompilationErrors() {
List<Diagnostic> diagnostics = getErrorDiagnostics("modelvalidator", "compilationerror.bal", 1);
Assert.assertTrue(diagnostics.size() == 1);
}

@Test(enabled = true)
public void validateCharAnnotations() {
List<Diagnostic> diagnostics = getErrorDiagnostics("modelvalidator", "char.bal", 3);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you 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.

import ballerina/persist as _;

public type Person record {|
readonly int nic;
string name;
int age;
string city;
any 'type;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
import static io.ballerina.stdlib.persist.sql.compiler.DiagnosticsCodes.PERSIST_SQL_619;
import static io.ballerina.stdlib.persist.sql.compiler.DiagnosticsCodes.PERSIST_SQL_620;
import static io.ballerina.stdlib.persist.sql.compiler.DiagnosticsCodes.PERSIST_SQL_621;
import static io.ballerina.stdlib.persist.sql.compiler.utils.Utils.getTypeName;
import static io.ballerina.stdlib.persist.sql.compiler.utils.Utils.hasCompilationErrors;
import static io.ballerina.stdlib.persist.sql.compiler.utils.Utils.isAnnotationPresent;
import static io.ballerina.stdlib.persist.sql.compiler.utils.Utils.readStringArrayValueFromAnnotation;
Expand Down Expand Up @@ -405,7 +404,9 @@ private void processEntityFields(Entity entity) {
isSimpleType = true;
}
} else {
fieldType = getTypeName(processedTypeNode);
// types like rest, anydata, any etc are not supported fields. hence ignored as they will be picked up
// by persist compiler
continue;
}

if (isIdentityField) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import io.ballerina.compiler.syntax.tree.ExpressionNode;
import io.ballerina.compiler.syntax.tree.MappingConstructorExpressionNode;
import io.ballerina.compiler.syntax.tree.MappingFieldNode;
import io.ballerina.compiler.syntax.tree.Node;
import io.ballerina.compiler.syntax.tree.SpecificFieldNode;
import io.ballerina.projects.plugins.SyntaxNodeAnalysisContext;
import io.ballerina.tools.diagnostics.Diagnostic;
Expand Down Expand Up @@ -54,14 +53,6 @@ public static String stripEscapeCharacter(String name) {
return name.startsWith("'") ? name.substring(1) : name;
}

Check warning on line 54 in compiler-plugin/src/main/java/io/ballerina/stdlib/persist/sql/compiler/utils/Utils.java

View check run for this annotation

Codecov / codecov/patch

compiler-plugin/src/main/java/io/ballerina/stdlib/persist/sql/compiler/utils/Utils.java#L54

Added line #L54 was not covered by tests

public static String getTypeName(Node processedTypeNode) {
String typeName = processedTypeNode.kind().stringValue();
if (typeName.isBlank()) {
typeName = processedTypeNode.kind().name();
}
return typeName;
}

public static String readStringValueFromAnnotation

Check warning on line 56 in compiler-plugin/src/main/java/io/ballerina/stdlib/persist/sql/compiler/utils/Utils.java

View check run for this annotation

Codecov / codecov/patch

compiler-plugin/src/main/java/io/ballerina/stdlib/persist/sql/compiler/utils/Utils.java#L56

Added line #L56 was not covered by tests
(List<AnnotationNode> annotationNodes, String annotation,
String field) {
Expand Down

0 comments on commit d5247ea

Please sign in to comment.