@@ -20,14 +20,142 @@ public static void AssertCoverage(bool x)
20
20
if ( ! ( x ) ) {
21
21
throw new Dafny . HaltException ( "Backends/Rust/Dafny-compiler-rust-coverage.dfy(26,4): " + Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( "expectation violation" ) . ToVerbatimString ( false ) ) ; }
22
22
}
23
+ public static void AssertEq < __T > ( __T x , __T y )
24
+ {
25
+ if ( ! ( object . Equals ( x , y ) ) ) {
26
+ throw new Dafny . HaltException ( "Backends/Rust/Dafny-compiler-rust-coverage.dfy(30,4): " + Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( "expectation violation" ) . ToVerbatimString ( false ) ) ; }
27
+ }
23
28
public static void TestExpr ( )
24
29
{
25
30
RASTCoverage . __default . TestOptimizeToString ( ) ;
26
31
RASTCoverage . __default . TestPrintingInfo ( ) ;
27
32
RASTCoverage . __default . TestNoExtraSemicolonAfter ( ) ;
33
+ RASTCoverage . __default . TestDocstring ( ) ;
34
+ }
35
+ public static Dafny . ISequence < Dafny . Rune > CanonicalNewlines ( Dafny . ISequence < Dafny . Rune > s ) {
36
+ Dafny . ISequence < Dafny . Rune > _0___accumulator = Dafny . Sequence < Dafny . Rune > . FromElements ( ) ;
37
+ TAIL_CALL_START : ;
38
+ if ( ( new BigInteger ( ( s ) . Count ) ) . Sign == 0 ) {
39
+ return Dafny . Sequence < Dafny . Rune > . Concat ( _0___accumulator , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( "" ) ) ;
40
+ } else if ( ( ( s ) . Select ( BigInteger . Zero ) ) == ( new Dafny . Rune ( '\r ' ) ) ) {
41
+ if ( ( ( new BigInteger ( ( s ) . Count ) ) > ( BigInteger . One ) ) && ( ( ( s ) . Select ( BigInteger . One ) ) == ( new Dafny . Rune ( '\n ' ) ) ) ) {
42
+ _0___accumulator = Dafny . Sequence < Dafny . Rune > . Concat ( _0___accumulator , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( "\n " ) ) ;
43
+ Dafny . ISequence < Dafny . Rune > _in0 = ( s ) . Drop ( new BigInteger ( 2 ) ) ;
44
+ s = _in0 ;
45
+ goto TAIL_CALL_START ;
46
+ } else {
47
+ _0___accumulator = Dafny . Sequence < Dafny . Rune > . Concat ( _0___accumulator , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( "\n " ) ) ;
48
+ Dafny . ISequence < Dafny . Rune > _in1 = ( s ) . Drop ( BigInteger . One ) ;
49
+ s = _in1 ;
50
+ goto TAIL_CALL_START ;
51
+ }
52
+ } else {
53
+ _0___accumulator = Dafny . Sequence < Dafny . Rune > . Concat ( _0___accumulator , ( s ) . Take ( BigInteger . One ) ) ;
54
+ Dafny . ISequence < Dafny . Rune > _in2 = ( s ) . Drop ( BigInteger . One ) ;
55
+ s = _in2 ;
56
+ goto TAIL_CALL_START ;
57
+ }
58
+ }
59
+ public static void TestOneDocstring ( Dafny . ISequence < Dafny . Rune > dafnyDocstring , Dafny . ISequence < Dafny . Rune > rustDocstring , Dafny . ISequence < Dafny . Rune > indent )
60
+ {
61
+ RASTCoverage . __default . AssertEq < Dafny . ISequence < Dafny . Rune > > ( RAST . __default . ConvertDocstring ( RASTCoverage . __default . CanonicalNewlines ( dafnyDocstring ) , indent , true , Std . Wrappers . Option < Dafny . ISequence < Dafny . Rune > > . create_None ( ) ) , RASTCoverage . __default . CanonicalNewlines ( rustDocstring ) ) ;
62
+ }
63
+ public static void TestDocstring ( )
64
+ {
65
+ RASTCoverage . __default . TestOneDocstring ( Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( @"
66
+ Hello
67
+ World" ) , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( @"
68
+ /// Hello
69
+ /// World" ) , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( " " ) ) ;
70
+ RASTCoverage . __default . TestOneDocstring ( Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( @"
71
+ Title
72
+ ```rs
73
+ let mut x = 1;
74
+ ```
75
+ End comment" ) , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( @"
76
+ /// Title
77
+ /// ```
78
+ /// let mut x = 1;
79
+ /// ```
80
+ /// End comment" ) , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( " " ) ) ;
81
+ RASTCoverage . __default . TestOneDocstring ( Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( @"
82
+ Title
83
+ `````rs
84
+ let mut x = 1;
85
+ `````
86
+ End comment" ) , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( @"
87
+ /// Title
88
+ /// `````
89
+ /// let mut x = 1;
90
+ /// `````
91
+ /// End comment" ) , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( " " ) ) ;
92
+ RASTCoverage . __default . TestOneDocstring ( Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( @"
93
+ Title
94
+ ```
95
+ var x := 1;
96
+ ```
97
+ End comment" ) , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( @"
98
+ /// Title
99
+ /// ```dafny
100
+ /// var x := 1;
101
+ /// ```
102
+ /// End comment" ) , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( " " ) ) ;
103
+ RASTCoverage . __default . TestOneDocstring ( Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( @"
104
+ Title
105
+ `````
106
+ var x := 1;
107
+ `````
108
+ End comment" ) , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( @"
109
+ /// Title
110
+ /// `````dafny
111
+ /// var x := 1;
112
+ /// `````
113
+ /// End comment" ) , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( " " ) ) ;
114
+ RASTCoverage . __default . TestOneDocstring ( Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( @"
115
+ Title
116
+ `````md
117
+ # title
118
+ ```
119
+ code
120
+ ```
121
+ Outside of code
122
+ `````
123
+ ```
124
+ dafnycode
125
+ ```
126
+ End comment" ) , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( @"
127
+ /// Title
128
+ /// `````md
129
+ /// # title
130
+ /// ```
131
+ /// code
132
+ /// ```
133
+ /// Outside of code
134
+ /// `````
135
+ /// ```dafny
136
+ /// dafnycode
137
+ /// ```
138
+ /// End comment" ) , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( " " ) ) ;
139
+ RASTCoverage . __default . TestOneDocstring ( Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( @"
140
+ Title
141
+ Indented code
142
+ More indented code
143
+ Back to normal
144
+ Normal as well
145
+ Also normal
146
+ But this one indented" ) , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( @"
147
+ /// Title
148
+ /// | Indented code
149
+ /// | More indented code
150
+ /// Back to normal
151
+ /// Normal as well
152
+ /// Also normal
153
+ /// | But this one indented" ) , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( " " ) ) ;
28
154
}
29
155
public static void TestNoOptimize ( RAST . _IExpr e )
30
156
{
157
+ if ( ! ( object . Equals ( ( RASTCoverage . __default . ExprSimp ) . ReplaceExpr ( e ) , e ) ) ) {
158
+ throw new Dafny . HaltException ( "Backends/Rust/Dafny-compiler-rust-coverage.dfy(157,4): " + Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( "expectation violation" ) . ToVerbatimString ( false ) ) ; }
31
159
}
32
160
public static RAST . _IExpr ConversionNum ( RAST . _IType t , RAST . _IExpr x )
33
161
{
@@ -161,5 +289,8 @@ public static void TestNoExtraSemicolonAfter()
161
289
RASTCoverage . __default . AssertCoverage ( ( RAST . Expr . create_DeclareVar ( RAST . DeclareType . create_MUT ( ) , Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( "x" ) , Std . Wrappers . Option < RAST . _IType > . create_None ( ) , Std . Wrappers . Option < RAST . _IExpr > . create_None ( ) ) ) . NoExtraSemicolonAfter ( ) ) ;
162
290
RASTCoverage . __default . AssertCoverage ( ! ( ( RAST . Expr . create_Identifier ( Dafny . Sequence < Dafny . Rune > . UnicodeFromString ( "x" ) ) ) . NoExtraSemicolonAfter ( ) ) ) ;
163
291
}
292
+ public static RAST . _IRASTBottomUpReplacer ExprSimp { get {
293
+ return ExpressionOptimization . __default . ExprSimplifier ( ) ;
294
+ } }
164
295
}
165
296
} // end of namespace RASTCoverage
0 commit comments