|
103 | 103 | (is (= ["Map"] (#'sut/extract-params "transform(Map<String,List<Integer>> data)")))) |
104 | 104 |
|
105 | 105 | (testing "multiple params with nested generics" |
106 | | - (is (= ["java.util.Map" "java.util.Map"] |
| 106 | + (is (= ["java.util.Map" "java.util.Map"] |
107 | 107 | (#'sut/extract-params "run(java.util.Map<java.lang.String, ? extends OnnxTensorLike> inputs, java.util.Map<java.lang.String, ? extends OnnxValue> pinnedOutputs)")))) |
108 | 108 |
|
109 | 109 | (testing "array types" |
|
248 | 248 | (is (true? (#'sut/params-match? ["int" "String"] '[int _]))) |
249 | 249 | (is (false? (#'sut/params-match? ["int" "String"] '[_]))) |
250 | 250 | (is (true? (#'sut/params-match? ["CharSequence..." "CharSequence..."] '[_ CharSequence/1]))))) |
| 251 | + |
| 252 | +(deftest extract-id-params-test |
| 253 | + |
| 254 | + (testing "no parameters" |
| 255 | + (is (= [] (#'sut/extract-id-params "valueOf()" "valueOf")))) |
| 256 | + |
| 257 | + (testing "single parameter" |
| 258 | + (is (= ["int"] (#'sut/extract-id-params "valueOf(int)" "valueOf")))) |
| 259 | + |
| 260 | + (testing "single fully qualified parameter" |
| 261 | + (is (= ["java.lang.String"] (#'sut/extract-id-params "valueOf(java.lang.String)" "valueOf")))) |
| 262 | + |
| 263 | + (testing "multiple simple parameters" |
| 264 | + (is (= ["int" "int"] (#'sut/extract-id-params "substring(int,int)" "substring")))) |
| 265 | + |
| 266 | + (testing "multiple fully qualified parameters" |
| 267 | + (is (= ["java.util.Map" "java.util.Set"] (#'sut/extract-id-params "run(java.util.Map,java.util.Set)" "run")))) |
| 268 | + |
| 269 | + (testing "array parameters" |
| 270 | + (is (= ["char[]"] (#'sut/extract-id-params "valueOf(char[])" "valueOf")))) |
| 271 | + |
| 272 | + (testing "mixed simple and qualified parameters" |
| 273 | + (is (= ["java.util.Map" "int"] (#'sut/extract-id-params "process(java.util.Map,int)" "process")))) |
| 274 | + |
| 275 | + (testing "inner class parameters with dot separator" |
| 276 | + (is (= ["ai.onnxruntime.OrtSession.RunOptions"] |
| 277 | + (#'sut/extract-id-params "run(ai.onnxruntime.OrtSession.RunOptions)" "run")))) |
| 278 | + |
| 279 | + (testing "non-matching method name returns nil" |
| 280 | + (is (nil? (#'sut/extract-id-params "valueOf(int)" "substring"))))) |
| 281 | + |
| 282 | +(deftest params-match-id-test |
| 283 | + |
| 284 | + (testing "exact match with simple types" |
| 285 | + (is (true? (#'sut/params-match-id? ["int"] ["int"]))) |
| 286 | + (is (true? (#'sut/params-match-id? ["int" "String"] ["int" "String"])))) |
| 287 | + |
| 288 | + (testing "simple type matches fully qualified type" |
| 289 | + (is (true? (#'sut/params-match-id? ["String"] ["java.lang.String"]))) |
| 290 | + (is (true? (#'sut/params-match-id? ["Map"] ["java.util.Map"]))) |
| 291 | + (is (true? (#'sut/params-match-id? ["Set"] ["java.util.Set"])))) |
| 292 | + |
| 293 | + (testing "multiple params with mixed simple and qualified" |
| 294 | + (is (true? (#'sut/params-match-id? ["Map" "Set"] ["java.util.Map" "java.util.Set"]))) |
| 295 | + (is (true? (#'sut/params-match-id? ["String" "int"] ["java.lang.String" "int"])))) |
| 296 | + |
| 297 | + (testing "array types match" |
| 298 | + (is (true? (#'sut/params-match-id? ["char[]"] ["char[]"]))) |
| 299 | + (is (true? (#'sut/params-match-id? ["String[]"] ["java.lang.String[]"])))) |
| 300 | + |
| 301 | + (testing "inner class with dot separator" |
| 302 | + (is (true? (#'sut/params-match-id? ["OrtSession.RunOptions"] ["ai.onnxruntime.OrtSession.RunOptions"])))) |
| 303 | + |
| 304 | + (testing "simple inner class name matches fully qualified" |
| 305 | + (is (true? (#'sut/params-match-id? ["RunOptions"] ["ai.onnxruntime.OrtSession.RunOptions"])))) |
| 306 | + |
| 307 | + (testing "wrong type does not match" |
| 308 | + (is (false? (#'sut/params-match-id? ["int"] ["String"]))) |
| 309 | + (is (false? (#'sut/params-match-id? ["Map"] ["java.util.Set"])))) |
| 310 | + |
| 311 | + (testing "wrong count does not match" |
| 312 | + (is (false? (#'sut/params-match-id? ["int"] ["int" "String"]))) |
| 313 | + (is (false? (#'sut/params-match-id? ["int" "String"] ["int"])))) |
| 314 | + |
| 315 | + (testing "empty params match" |
| 316 | + (is (true? (#'sut/params-match-id? [] []))))) |
| 317 | + |
| 318 | +(deftest find-method-section-test |
| 319 | + |
| 320 | + (testing "finds method with simple type parameters" |
| 321 | + (let [html "<html><body> |
| 322 | + <section id='valueOf(int)'> |
| 323 | + <h3>valueOf</h3> |
| 324 | + </section> |
| 325 | + <section id='valueOf(char[])'> |
| 326 | + <h3>valueOf</h3> |
| 327 | + </section> |
| 328 | + </body></html>" |
| 329 | + doc (Jsoup/parse html) |
| 330 | + section-int (#'sut/find-method-section doc "valueOf" ["int"]) |
| 331 | + section-char-array (#'sut/find-method-section doc "valueOf" ["char[]"])] |
| 332 | + (is (= "valueOf(int)" (.attr section-int "id"))) |
| 333 | + (is (= "valueOf(char[])" (.attr section-char-array "id"))))) |
| 334 | + |
| 335 | + (testing "finds method with fully qualified type parameters" |
| 336 | + (let [html "<html><body> |
| 337 | + <section id='run(java.util.Map)'> |
| 338 | + <h3>run</h3> |
| 339 | + </section> |
| 340 | + <section id='run(java.util.Map,java.util.Set)'> |
| 341 | + <h3>run</h3> |
| 342 | + </section> |
| 343 | + </body></html>" |
| 344 | + doc (Jsoup/parse html) |
| 345 | + section-map (#'sut/find-method-section doc "run" ["Map"]) |
| 346 | + section-map-set (#'sut/find-method-section doc "run" ["Map" "Set"])] |
| 347 | + (is (= "run(java.util.Map)" (.attr section-map "id"))) |
| 348 | + (is (= "run(java.util.Map,java.util.Set)" (.attr section-map-set "id"))))) |
| 349 | + |
| 350 | + (testing "finds method with no parameters, nil from extract-params" |
| 351 | + (let [html "<html><body> |
| 352 | + <section id='length()'> |
| 353 | + <h3>length</h3> |
| 354 | + </section> |
| 355 | + </body></html>" |
| 356 | + doc (Jsoup/parse html) |
| 357 | + section (#'sut/find-method-section doc "length" nil)] |
| 358 | + (is (= "length()" (.attr section "id"))))) |
| 359 | + |
| 360 | + (testing "finds method with no parameters, empty vector" |
| 361 | + (let [html "<html><body> |
| 362 | + <section id='toString()'> |
| 363 | + <h3>toString</h3> |
| 364 | + </section> |
| 365 | + </body></html>" |
| 366 | + doc (Jsoup/parse html) |
| 367 | + section (#'sut/find-method-section doc "toString" [])] |
| 368 | + (is (= "toString()" (.attr section "id"))))) |
| 369 | + |
| 370 | + (testing "returns nil when method not found" |
| 371 | + (let [html "<html><body> |
| 372 | + <section id='valueOf(int)'> |
| 373 | + <h3>valueOf</h3> |
| 374 | + </section> |
| 375 | + </body></html>" |
| 376 | + doc (Jsoup/parse html)] |
| 377 | + (is (nil? (#'sut/find-method-section doc "valueOf" ["String"]))) |
| 378 | + (is (nil? (#'sut/find-method-section doc "nonExistent" ["int"]))))) |
| 379 | + |
| 380 | + (testing "distinguishes between overloads with different param counts" |
| 381 | + (let [html "<html><body> |
| 382 | + <section id='run(java.util.Map)'> |
| 383 | + <h3>run</h3> |
| 384 | + </section> |
| 385 | + <section id='run(java.util.Map,java.util.Set)'> |
| 386 | + <h3>run</h3> |
| 387 | + </section> |
| 388 | + <section id='run(java.util.Map,java.util.Set,ai.onnxruntime.OrtSession.RunOptions)'> |
| 389 | + <h3>run</h3> |
| 390 | + </section> |
| 391 | + </body></html>" |
| 392 | + doc (Jsoup/parse html) |
| 393 | + section-1 (#'sut/find-method-section doc "run" ["Map"]) |
| 394 | + section-2 (#'sut/find-method-section doc "run" ["Map" "Set"]) |
| 395 | + section-3 (#'sut/find-method-section doc "run" ["Map" "Set" "OrtSession.RunOptions"])] |
| 396 | + (is (= "run(java.util.Map)" (.attr section-1 "id"))) |
| 397 | + (is (= "run(java.util.Map,java.util.Set)" (.attr section-2 "id"))) |
| 398 | + (is (= "run(java.util.Map,java.util.Set,ai.onnxruntime.OrtSession.RunOptions)" (.attr section-3 "id")))))) |
0 commit comments