@@ -2024,6 +2024,226 @@ fn main() {
2024
2024
'(" r#\"\"\" #" font-lock-string-face
2025
2025
" 'q'" font-lock-string-face )))
2026
2026
2027
+ (ert-deftest rust-macro-font-lock ()
2028
+ (rust-test-font-lock
2029
+ " foo!\(\) ;"
2030
+ '(" foo!" font-lock-preprocessor-face ))
2031
+ (rust-test-font-lock
2032
+ " foo!{};"
2033
+ '(" foo!" font-lock-preprocessor-face ))
2034
+ (rust-test-font-lock
2035
+ " foo![];"
2036
+ '(" foo!" font-lock-preprocessor-face )))
2037
+
2038
+ (ert-deftest rust-string-interpolation-matcher-works ()
2039
+ (dolist (test '((" print!\(\"\"\) " 9 11 nil )
2040
+ (" print!\(\" abcd\"\) " 9 15 nil )
2041
+ (" print!\(\" abcd {{}}\"\) ;" 9 19 nil )
2042
+ (" print!\(\" abcd {{\"\) ;" 9 18 nil )
2043
+ (" print!\(\" abcd {}\"\) ;" 9 18 ((14 16 )))
2044
+ (" print!\(\" abcd {{{}\"\) ;" 9 20 ((16 18 )))
2045
+ (" print!\(\" abcd {}{{\"\) ;" 9 20 ((14 16 )))
2046
+ (" print!\(\" abcd {} {{\"\) ;" 9 21 ((14 16 )))
2047
+ (" print!\(\" abcd {}}}\"\) ;" 9 20 ((14 16 )))
2048
+ (" print!\(\" abcd {{{}}}\"\) ;" 9 20 ((16 18 )))
2049
+ (" print!\(\" abcd {0}\"\) ;" 9 18 ((14 17 )))
2050
+ (" print!\(\" abcd {0} efgh\"\) ;" 9 23 ((14 17 )))
2051
+ (" print!\(\" {1} abcd {0} efgh\"\) ;" 9 27 ((9 12 ) (18 21 )))
2052
+ (" print!\(\" {{{1} abcd }} {0}}} {{efgh}}\"\) ;" 9 33 ((11 14 ) (23 26 )))))
2053
+ (destructuring-bind (text cursor limit matches) test
2054
+ (with-temp-buffer
2055
+ ; ; make sure we have a clean slate
2056
+ (save-match-data
2057
+ (set-match-data nil )
2058
+ (insert text)
2059
+ (goto-char cursor )
2060
+ (if (null matches)
2061
+ (should (equal (progn
2062
+ (rust-string-interpolation-matcher limit)
2063
+ (match-data ))
2064
+ nil ))
2065
+ (dolist (pair matches)
2066
+ (rust-string-interpolation-matcher limit)
2067
+ (should (equal (match-beginning 0 ) (car pair)))
2068
+ (should (equal (match-end 0 ) (cadr pair))))))))))
2069
+
2070
+ (ert-deftest rust-formatting-macro-font-lock ()
2071
+ ; ; test that the block delimiters aren't highlighted and the comment
2072
+ ; ; is ignored
2073
+ (rust-test-font-lock
2074
+ " print!(\"\" ); { /* print!(\"\" ); */ }"
2075
+ '(" print!" rust-builtin-formatting-macro-face
2076
+ " \"\" " font-lock-string-face
2077
+ " /* " font-lock-comment-delimiter-face
2078
+ " print!(\"\" ); */" font-lock-comment-face ))
2079
+ ; ; other delimiters
2080
+ (rust-test-font-lock
2081
+ " print!{\"\" }; { /* no-op */ }"
2082
+ '(" print!" rust-builtin-formatting-macro-face
2083
+ " \"\" " font-lock-string-face
2084
+ " /* " font-lock-comment-delimiter-face
2085
+ " no-op */" font-lock-comment-face ))
2086
+ ; ; other delimiters
2087
+ (rust-test-font-lock
2088
+ " print![\"\" ]; { /* no-op */ }"
2089
+ '(" print!" rust-builtin-formatting-macro-face
2090
+ " \"\" " font-lock-string-face
2091
+ " /* " font-lock-comment-delimiter-face
2092
+ " no-op */" font-lock-comment-face ))
2093
+ ; ; no interpolation
2094
+ (rust-test-font-lock
2095
+ " print!(\" abcd\" ); { /* no-op */ }"
2096
+ '(" print!" rust-builtin-formatting-macro-face
2097
+ " \" abcd\" " font-lock-string-face
2098
+ " /* " font-lock-comment-delimiter-face
2099
+ " no-op */" font-lock-comment-face ))
2100
+ ; ; only interpolation
2101
+ (rust-test-font-lock
2102
+ " print!(\" {}\" ); { /* no-op */ }"
2103
+ '(" print!" rust-builtin-formatting-macro-face
2104
+ " \" " font-lock-string-face
2105
+ " {}" rust-string-interpolation-face
2106
+ " \" " font-lock-string-face
2107
+ " /* " font-lock-comment-delimiter-face
2108
+ " no-op */" font-lock-comment-face ))
2109
+ ; ; text + interpolation
2110
+ (rust-test-font-lock
2111
+ " print!(\" abcd {}\" , foo); { /* no-op */ }"
2112
+ '(" print!" rust-builtin-formatting-macro-face
2113
+ " \" abcd " font-lock-string-face
2114
+ " {}" rust-string-interpolation-face
2115
+ " \" " font-lock-string-face
2116
+ " /* " font-lock-comment-delimiter-face
2117
+ " no-op */" font-lock-comment-face ))
2118
+ ; ; text + interpolation with specification
2119
+ (rust-test-font-lock
2120
+ " print!(\" abcd {0}\" , foo); { /* no-op */ }"
2121
+ '(" print!" rust-builtin-formatting-macro-face
2122
+ " \" abcd " font-lock-string-face
2123
+ " {0}" rust-string-interpolation-face
2124
+ " \" " font-lock-string-face
2125
+ " /* " font-lock-comment-delimiter-face
2126
+ " no-op */" font-lock-comment-face ))
2127
+ ; ; text + interpolation with specification and escape
2128
+ (rust-test-font-lock
2129
+ " print!(\" abcd {0}}}\" , foo); { /* no-op */ }"
2130
+ '(" print!" rust-builtin-formatting-macro-face
2131
+ " \" abcd " font-lock-string-face
2132
+ " {0}" rust-string-interpolation-face
2133
+ " }}\" " font-lock-string-face
2134
+ " /* " font-lock-comment-delimiter-face
2135
+ " no-op */" font-lock-comment-face ))
2136
+ ; ; multiple pairs
2137
+ (rust-test-font-lock
2138
+ " print!(\" abcd {0} efgh {1}\" , foo, bar); { /* no-op */ }"
2139
+ '(" print!" rust-builtin-formatting-macro-face
2140
+ " \" abcd " font-lock-string-face
2141
+ " {0}" rust-string-interpolation-face
2142
+ " efgh " font-lock-string-face
2143
+ " {1}" rust-string-interpolation-face
2144
+ " \" " font-lock-string-face
2145
+ " /* " font-lock-comment-delimiter-face
2146
+ " no-op */" font-lock-comment-face ))
2147
+ ; ; println
2148
+ (rust-test-font-lock
2149
+ " println!(\" abcd {0} efgh {1}\" , foo, bar); { /* no-op */ }"
2150
+ '(" println!" rust-builtin-formatting-macro-face
2151
+ " \" abcd " font-lock-string-face
2152
+ " {0}" rust-string-interpolation-face
2153
+ " efgh " font-lock-string-face
2154
+ " {1}" rust-string-interpolation-face
2155
+ " \" " font-lock-string-face
2156
+ " /* " font-lock-comment-delimiter-face
2157
+ " no-op */" font-lock-comment-face ))
2158
+ ; ; eprint
2159
+ (rust-test-font-lock
2160
+ " eprint!(\" abcd {0} efgh {1}\" , foo, bar); { /* no-op */ }"
2161
+ '(" eprint!" rust-builtin-formatting-macro-face
2162
+ " \" abcd " font-lock-string-face
2163
+ " {0}" rust-string-interpolation-face
2164
+ " efgh " font-lock-string-face
2165
+ " {1}" rust-string-interpolation-face
2166
+ " \" " font-lock-string-face
2167
+ " /* " font-lock-comment-delimiter-face
2168
+ " no-op */" font-lock-comment-face ))
2169
+ ; ; eprintln
2170
+ (rust-test-font-lock
2171
+ " eprintln!(\" abcd {0} efgh {1}\" , foo, bar); { /* no-op */ }"
2172
+ '(" eprintln!" rust-builtin-formatting-macro-face
2173
+ " \" abcd " font-lock-string-face
2174
+ " {0}" rust-string-interpolation-face
2175
+ " efgh " font-lock-string-face
2176
+ " {1}" rust-string-interpolation-face
2177
+ " \" " font-lock-string-face
2178
+ " /* " font-lock-comment-delimiter-face
2179
+ " no-op */" font-lock-comment-face ))
2180
+ ; ; format
2181
+ (rust-test-font-lock
2182
+ " format!(\" abcd {0} efgh {1}\" , foo, bar); { /* no-op */ }"
2183
+ '(" format!" rust-builtin-formatting-macro-face
2184
+ " \" abcd " font-lock-string-face
2185
+ " {0}" rust-string-interpolation-face
2186
+ " efgh " font-lock-string-face
2187
+ " {1}" rust-string-interpolation-face
2188
+ " \" " font-lock-string-face
2189
+ " /* " font-lock-comment-delimiter-face
2190
+ " no-op */" font-lock-comment-face ))
2191
+ ; ; print + raw string
2192
+ (rust-test-font-lock
2193
+ " format!(r\" abcd {0} efgh {1}\" , foo, bar); { /* no-op */ }"
2194
+ '(" format!" rust-builtin-formatting-macro-face
2195
+ " r\" abcd " font-lock-string-face
2196
+ " {0}" rust-string-interpolation-face
2197
+ " efgh " font-lock-string-face
2198
+ " {1}" rust-string-interpolation-face
2199
+ " \" " font-lock-string-face
2200
+ " /* " font-lock-comment-delimiter-face
2201
+ " no-op */" font-lock-comment-face ))
2202
+ ; ; print + raw string with hash
2203
+ (rust-test-font-lock
2204
+ " format!(r#\" abcd {0} efgh {1}\" #, foo, bar); { /* no-op */ }"
2205
+ '(" format!" rust-builtin-formatting-macro-face
2206
+ " r#\" abcd " font-lock-string-face
2207
+ " {0}" rust-string-interpolation-face
2208
+ " efgh " font-lock-string-face
2209
+ " {1}" rust-string-interpolation-face
2210
+ " \" #" font-lock-string-face
2211
+ " /* " font-lock-comment-delimiter-face
2212
+ " no-op */" font-lock-comment-face ))
2213
+ ; ; print + raw string with two hashes
2214
+ (rust-test-font-lock
2215
+ " format!(r##\" abcd {0} efgh {1}\" ##, foo, bar); { /* no-op */ }"
2216
+ '(" format!" rust-builtin-formatting-macro-face
2217
+ " r##\" abcd " font-lock-string-face
2218
+ " {0}" rust-string-interpolation-face
2219
+ " efgh " font-lock-string-face
2220
+ " {1}" rust-string-interpolation-face
2221
+ " \" ##" font-lock-string-face
2222
+ " /* " font-lock-comment-delimiter-face
2223
+ " no-op */" font-lock-comment-face )))
2224
+
2225
+ (ert-deftest rust-write-macro-font-lock ()
2226
+ (rust-test-font-lock
2227
+ " write!(f, \" abcd {0}}} efgh {1}\" , foo, bar); { /* no-op */ }"
2228
+ '(" write!" rust-builtin-formatting-macro-face
2229
+ " \" abcd " font-lock-string-face
2230
+ " {0}" rust-string-interpolation-face
2231
+ " }} efgh " font-lock-string-face
2232
+ " {1}" rust-string-interpolation-face
2233
+ " \" " font-lock-string-face
2234
+ " /* " font-lock-comment-delimiter-face
2235
+ " no-op */" font-lock-comment-face ))
2236
+ (rust-test-font-lock
2237
+ " writeln!(f, \" abcd {0}}} efgh {1}\" , foo, bar); { /* no-op */ }"
2238
+ '(" writeln!" rust-builtin-formatting-macro-face
2239
+ " \" abcd " font-lock-string-face
2240
+ " {0}" rust-string-interpolation-face
2241
+ " }} efgh " font-lock-string-face
2242
+ " {1}" rust-string-interpolation-face
2243
+ " \" " font-lock-string-face
2244
+ " /* " font-lock-comment-delimiter-face
2245
+ " no-op */" font-lock-comment-face )))
2246
+
2027
2247
(ert-deftest rust-test-basic-paren-matching ()
2028
2248
(rust-test-matching-parens
2029
2249
"
0 commit comments