@@ -1447,12 +1447,11 @@ mod given_interpreter {
1447
1447
}
1448
1448
1449
1449
fn is_unit_with_output ( result : & InterpretResult , output : & str , expected_output : & str ) {
1450
- assert_eq ! ( expected_output, output) ;
1451
-
1452
1450
match result {
1453
1451
Ok ( value) => assert_eq ! ( Value :: unit( ) , * value) ,
1454
1452
Err ( e) => panic ! ( "Expected unit value, got {e:?}" ) ,
1455
1453
}
1454
+ assert_eq ! ( expected_output, output) ;
1456
1455
}
1457
1456
1458
1457
fn is_only_error < E > ( result : & Result < Value , Vec < E > > , output : & str , expected_errors : & Expect )
@@ -2089,5 +2088,73 @@ mod given_interpreter {
2089
2088
entry : None ,
2090
2089
}
2091
2090
}
2091
+
2092
+ #[ test]
2093
+ fn name_resolution_from_source_named_main_should_succeed ( ) {
2094
+ let sources = SourceMap :: new (
2095
+ [ (
2096
+ "Main" . into ( ) ,
2097
+ r#"function Foo() : Unit { Message("hello there..."); }"# . into ( ) ,
2098
+ ) ] ,
2099
+ None ,
2100
+ ) ;
2101
+ let ( std_id, store) =
2102
+ crate :: compile:: package_store_with_stdlib ( TargetCapabilityFlags :: all ( ) ) ;
2103
+ let mut interpreter = Interpreter :: new (
2104
+ sources,
2105
+ PackageType :: Lib ,
2106
+ TargetCapabilityFlags :: all ( ) ,
2107
+ LanguageFeatures :: default ( ) ,
2108
+ store,
2109
+ & [ ( std_id, None ) ] ,
2110
+ )
2111
+ . expect ( "interpreter should be created" ) ;
2112
+
2113
+ // Operations defined in Main.qs should also be visible with Main qualifier.
2114
+ let ( result, output) = line ( & mut interpreter, "Main.Foo()" ) ;
2115
+ is_unit_with_output ( & result, & output, "hello there..." ) ;
2116
+
2117
+ // Operations defined in Main.qs should be importable with fully qualified name.
2118
+ let ( result, output) = line ( & mut interpreter, "import Main.Foo;" ) ;
2119
+ is_only_value ( & result, & output, & Value :: unit ( ) ) ;
2120
+
2121
+ // After import the operation can be invoked without Main qualifier.
2122
+ let ( result, output) = line ( & mut interpreter, "Foo()" ) ;
2123
+ is_unit_with_output ( & result, & output, "hello there..." ) ;
2124
+ }
2125
+
2126
+ #[ test]
2127
+ fn name_resolution_from_source_named_main_without_full_path_or_import_should_fail ( ) {
2128
+ let sources = SourceMap :: new (
2129
+ [ (
2130
+ "Main" . into ( ) ,
2131
+ r#"function Foo() : Unit { Message("hello there..."); }"# . into ( ) ,
2132
+ ) ] ,
2133
+ None ,
2134
+ ) ;
2135
+ let ( std_id, store) =
2136
+ crate :: compile:: package_store_with_stdlib ( TargetCapabilityFlags :: all ( ) ) ;
2137
+ let mut interpreter = Interpreter :: new (
2138
+ sources,
2139
+ PackageType :: Lib ,
2140
+ TargetCapabilityFlags :: all ( ) ,
2141
+ LanguageFeatures :: default ( ) ,
2142
+ store,
2143
+ & [ ( std_id, None ) ] ,
2144
+ )
2145
+ . expect ( "interpreter should be created" ) ;
2146
+
2147
+ // Operations defined in Main.qs should also be visible with Main qualifier.
2148
+ let ( errors, _) = line ( & mut interpreter, "Foo()" ) ;
2149
+ is_error (
2150
+ & errors. expect_err ( "line invocation should fail with error" ) ,
2151
+ & expect ! [ [ r#"
2152
+ name error: `Foo` not found
2153
+ [line_0] [Foo]
2154
+ type error: insufficient type information to infer type
2155
+ [line_0] [Foo()]
2156
+ "# ] ] ,
2157
+ ) ;
2158
+ }
2092
2159
}
2093
2160
}
0 commit comments