Skip to content

Commit

Permalink
Update tests for NFFrontEnd function changes.
Browse files Browse the repository at this point in the history
  - Add tests for user defined overloading
  • Loading branch information
mahge authored and OpenModelica-Hudson committed Mar 16, 2017
1 parent 984eeea commit 2b02a60
Show file tree
Hide file tree
Showing 15 changed files with 268 additions and 15 deletions.
6 changes: 3 additions & 3 deletions flattening/modelica/scodeinst/FuncBuiltinRem.mo
Expand Up @@ -14,8 +14,8 @@ end FuncBuiltinRem;

// Result:
// class FuncBuiltinRem
// Real r1 = rem(5, 2);
// Real r2 = rem(5.0, 2.0);
// Real r3 = rem(8.0, 3.0);
// Real r1 = OpenModelica.Internal.intRem(5, 2);
// Real r2 = OpenModelica.Internal.realRem(5.0, 2.0);
// Real r3 = OpenModelica.Internal.realRem(8.0, 3.0);
// end FuncBuiltinRem;
// endResult
3 changes: 3 additions & 0 deletions flattening/modelica/scodeinst/FuncIntegerWrongType.mo
Expand Up @@ -16,6 +16,9 @@ end FuncIntegerWrongType;
// Real
// expected type:
// enumeration(:)
// [flattening/modelica/scodeinst/FuncIntegerWrongType.mo:10:3-10:27:writable] Error: No matching function found for Integer(1) in component <REMOVE ME>
// candidates are :
// Integer(enumeration(:) $e) => Integer
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
Expand Down
3 changes: 3 additions & 0 deletions flattening/modelica/scodeinst/FuncMissingDefault1.mo
Expand Up @@ -19,6 +19,9 @@ end M;
// Result:
// Error processing file: FuncMissingDefault1.mo
// [flattening/modelica/scodeinst/FuncMissingDefault1.mo:16:3-16:18:writable] Error: Function parameter y was not given by the function call, and does not have a default value.
// [flattening/modelica/scodeinst/FuncMissingDefault1.mo:16:3-16:18:writable] Error: No matching function found for f(1) in component <REMOVE ME>
// candidates are :
// f(Real x, Real y) => Real
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
Expand Down
11 changes: 6 additions & 5 deletions flattening/modelica/scodeinst/FuncMissingDefault2.mo
Expand Up @@ -3,19 +3,21 @@
// status: correct
// cflags: -d=newInst
//
// Checks that a warning is given when a parameter that doesn't have a default
// argument is after a parameter that does.
// This is actaully valid (no warning needed). e.g. a call like this should work f(1.0, z=2.0)
// // Checks that a warning is given when a parameter that doesn't have a default
// // argument is after a parameter that does.
//

function f
input Real x;
input Real y = 1.0;
input Real z;
input Real z; // No warning needed
output Real w = x + y + z;
end f;

model M
Real x = f(1.0, 2.0, 3.0);
Real x = f(1.0, z=2.0);
end M;

// Result:
Expand All @@ -28,7 +30,6 @@ end M;
//
// class M
// Real x = f(1.0, 2.0, 3.0);
// Real x = f(1.0, 1.0, 2.0);
// end M;
// [flattening/modelica/scodeinst/FuncMissingDefault2.mo:13:3-13:15:writable] Warning: Missing default argument on function parameter z.
//
// endResult
37 changes: 37 additions & 0 deletions flattening/modelica/scodeinst/FuncOverloadAmbiguousDefault.mo
@@ -0,0 +1,37 @@
// name: FuncOverloadAmbiguousDefault
// keywords: overload
// status: incorrect
// cflags: -d=newInst
//
// Tests an ambigous overload due to default values.
//
model FuncOverloadAmbiguousDefault
function F
input Integer f1;
output Integer f2;
end F;

function G
input Integer g1;
input Integer g2 = 1;
output Integer g3;
end G;

function OV = $overload(F,G);

Integer x = OV(1);
end FuncOverloadAmbiguousDefault;

// Result:
// Ambiguous call: OV(1)
// Candidates:
// OV(Integer g1, Integer g2 = 1) => Integer
// OV(Integer f1) => Integer
// Error processing file: FuncOverloadAmbiguousDefault.mo
// Error: Internal error Instantiation of FuncOverloadAmbiguousDefault failed with no error message.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
43 changes: 43 additions & 0 deletions flattening/modelica/scodeinst/FuncOverloadExactPrefer.mo
@@ -0,0 +1,43 @@
// name: FuncOverloadExactPrefer
// keywords: overload, cast
// status: correct
// cflags: -d=newInst
//
// Tests proper selection of exact matches over converted matches.
// Compare with FuncOverloadAmbiguousDefault
//
model FuncOverloadExactPrefer
function F
input Integer f1;
output Integer f2;
end F;

function G
input Real g1;
input Integer g2 = 1;
output Integer g3;
end G;

function OV = $overload(F,G);

Integer x = OV(1);
Integer x = OV(1.0);
end FuncOverloadExactPrefer;

// Result:
// function F
// input Integer f1;
// output Integer f2;
// end F;
//
// function G
// input Real g1;
// input Integer g2 = 1;
// output Integer g3;
// end G;
//
// class FuncOverloadExactPrefer
// Integer x = F(1);
// Integer x = G(1.0, 1);
// end FuncOverloadExactPrefer;
// endResult
54 changes: 54 additions & 0 deletions flattening/modelica/scodeinst/FuncOverloadMulti.mo
@@ -0,0 +1,54 @@
// name: FuncOverloadMulti
// keywords: overload, cast
// status: correct
// cflags: -d=newInst
//
// Tests handling of multiple overload, i.e, and overload of overloaded function
//
model FuncOverloadMulti
function int_string
input Integer f1;
output String f2;
end int_string;

function real_string
input Real g1;
output Integer g3;
end real_string;

function numeric_string = $overload(int_string,real_string);

function bool_string
input Boolean g1;
output Integer g3;
end bool_string;

function any_string = $overload(numeric_string,bool_string);

String x = any_string(true);
String x = any_string(1);
String x = any_string(1.0);
end FuncOverloadMulti;

// Result:
// function bool_string
// input Boolean g1;
// output Integer g3;
// end bool_string;
//
// function int_string
// input Integer f1;
// output String f2;
// end int_string;
//
// function real_string
// input Real g1;
// output Integer g3;
// end real_string;
//
// class FuncOverloadMulti
// String x = bool_string(true);
// String x = int_string(1);
// String x = real_string(1.0);
// end FuncOverloadMulti;
// endResult
43 changes: 43 additions & 0 deletions flattening/modelica/scodeinst/FuncOverloadNoMatch.mo
@@ -0,0 +1,43 @@
// name: FuncOverloadNoMatch
// keywords: overload
// status: incorrect
// cflags: -d=newInst
//
// Tests that proper error messages are printed for no overload match
//
model FuncOverloadNoMatch
function F
input Integer f1;
output Integer f2;
end F;

function G
input Real g1;
output Integer g3;
end G;

function OV = $overload(F,G);

Integer x = OV(true);
end FuncOverloadNoMatch;

// Result:
// Error processing file: FuncOverloadNoMatch.mo
// [flattening/modelica/scodeinst/FuncOverloadNoMatch.mo:21:3-21:23:writable] Error: Type mismatch for positional argument 1 in F(f1=true). The argument has type:
// Boolean
// expected type:
// Integer
// [flattening/modelica/scodeinst/FuncOverloadNoMatch.mo:21:3-21:23:writable] Error: Type mismatch for positional argument 1 in G(g1=true). The argument has type:
// Boolean
// expected type:
// Real
// [flattening/modelica/scodeinst/FuncOverloadNoMatch.mo:21:3-21:23:writable] Error: No matching function found for OV(true) in component <REMOVE ME>
// candidates are :
// OV(Integer f1) => Integer
// OV(Real g1) => Integer
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
42 changes: 42 additions & 0 deletions flattening/modelica/scodeinst/FuncOverloadSimple.mo
@@ -0,0 +1,42 @@
// name: FuncSimpleOverload
// keywords: overload
// status: correct
// cflags: -d=newInst
//
// Tests simple overloading.
//
model FuncSimpleOverload
function F
input Integer f1;
output Integer f2;
end F;

function G
input Integer g1;
input Integer g2;
output Integer g3;
end G;

function OV = $overload(F,G);

Integer x = OV(1);
Integer y = OV(1,2);
end FuncSimpleOverload;

// Result:
// function F
// input Integer f1;
// output Integer f2;
// end F;
//
// function G
// input Integer g1;
// input Integer g2;
// output Integer g3;
// end G;
//
// class FuncSimpleOverload
// Integer x = F(1);
// Integer y = G(1, 2);
// end FuncSimpleOverload;
// endResult
4 changes: 2 additions & 2 deletions flattening/modelica/scodeinst/FuncString.mo
Expand Up @@ -12,7 +12,7 @@ model FuncString
String s1 = String(1);
String s2 = String(E.one);
String s3 = String(true);
String s4 = String(1.0);
String s4 = String(1.0, significantDigits = 3);
String s5 = String(1.0, format = "-0.4g");
String s6 = String(1, leftJustified = false, minimumLength = 3);
end FuncString;
Expand All @@ -22,7 +22,7 @@ end FuncString;
// String s1 = String(1, 0, true);
// String s2 = String(E.one, 0, true);
// String s3 = String(true, 0, true);
// String s4 = String(1.0, 6, 0, true);
// String s4 = String(1.0, 3, 0, true);
// String s5 = String(1.0, "-0.4g");
// String s6 = String(1, 3, false);
// end FuncString;
Expand Down
16 changes: 16 additions & 0 deletions flattening/modelica/scodeinst/FuncStringInvalid1.mo
Expand Up @@ -12,6 +12,22 @@ end FuncStringInvalid1;

// Result:
// Error processing file: FuncStringInvalid1.mo
// [flattening/modelica/scodeinst/FuncStringInvalid1.mo:10:3-10:31:writable] Error: Type mismatch for positional argument 1 in String(e={1, 2, 3}). The argument has type:
// Integer[3]
// expected type:
// enumeration(:)
// [flattening/modelica/scodeinst/FuncStringInvalid1.mo:10:3-10:31:writable] Error: Type mismatch for positional argument 1 in String(i={1, 2, 3}). The argument has type:
// Integer[3]
// expected type:
// Integer
// [flattening/modelica/scodeinst/FuncStringInvalid1.mo:10:3-10:31:writable] Error: Type mismatch for positional argument 1 in String(b={1, 2, 3}). The argument has type:
// Integer[3]
// expected type:
// Boolean
// [flattening/modelica/scodeinst/FuncStringInvalid1.mo:10:3-10:31:writable] Error: Type mismatch for positional argument 1 in String(r={1, 2, 3}). The argument has type:
// Integer[3]
// expected type:
// Real
// [flattening/modelica/scodeinst/FuncStringInvalid1.mo:10:3-10:31:writable] Error: No matching function found for String({1, 2, 3}) in component <REMOVE ME>
// candidates are :
// String(enumeration(:) $e, Integer minimumLength = 0, Boolean leftJustified = true) => String
Expand Down
10 changes: 5 additions & 5 deletions flattening/modelica/scodeinst/FuncStringInvalid2.mo
Expand Up @@ -15,11 +15,11 @@ end FuncStringInvalid2;
// Error processing file: FuncStringInvalid2.mo
// [flattening/modelica/scodeinst/FuncStringInvalid2.mo:11:3-11:33:writable] Error: No matching function found for String(1, false, 3) in component <REMOVE ME>
// candidates are :
// String($e, minimumLength = 0, leftJustified = true)
// String($i, minimumLength = 0, leftJustified = true)
// String($b, minimumLength = 0, leftJustified = true)
// String($r, significantDigits = 6, minimumLength = 0, leftJustified = true)
// String($r, format = "-0.6g")
// String(enumeration(:) $e, Integer minimumLength = 0, Boolean leftJustified = true) => String
// String(Integer $i, Integer minimumLength = 0, Boolean leftJustified = true) => String
// String(Boolean $b, Integer minimumLength = 0, Boolean leftJustified = true) => String
// String(Real $r, Integer significantDigits = 6, Integer minimumLength = 0, Boolean leftJustified = true) => String
// String(Real $r, String format = "-0.6g") => String
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
Expand Down
3 changes: 3 additions & 0 deletions flattening/modelica/scodeinst/FuncVariability.mo
Expand Up @@ -18,6 +18,9 @@ end FuncVariability;
// Result:
// Error processing file: FuncVariability.mo
// [flattening/modelica/scodeinst/FuncVariability.mo:15:3-15:19:writable] Error: Function argument x=time is not a parameter expression.
// [flattening/modelica/scodeinst/FuncVariability.mo:15:3-15:19:writable] Error: No matching function found for f(time) in component <REMOVE ME>
// candidates are :
// f(Real x) => Real
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
Expand Down
3 changes: 3 additions & 0 deletions flattening/modelica/scodeinst/FuncWrongType.mo
Expand Up @@ -21,6 +21,9 @@ end FuncWrongType;
// Boolean
// expected type:
// Real
// [flattening/modelica/scodeinst/FuncWrongType.mo:15:3-15:19:writable] Error: No matching function found for f(true) in component <REMOVE ME>
// candidates are :
// f(Real x) => Real
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
Expand Down
5 changes: 5 additions & 0 deletions flattening/modelica/scodeinst/Makefile
Expand Up @@ -80,6 +80,11 @@ FuncIntegerWrongType.mo \
FuncLocals.mo \
FuncMissingDefault1.mo \
FuncMissingDefault2.mo \
FuncOverloadAmbiguousDefault.mo \
FuncOverloadExactPrefer.mo \
FuncOverloadMulti.mo \
FuncOverloadNoMatch.mo \
FuncOverloadSimple.mo \
FuncSimple.mo \
FuncStringInvalid1.mo \
FuncStringInvalid2.mo \
Expand Down

0 comments on commit 2b02a60

Please sign in to comment.