method-ray 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -297,378 +297,3 @@ impl ScopeManager {
297
297
  }
298
298
  }
299
299
  }
300
-
301
- #[cfg(test)]
302
- mod tests {
303
- use super::*;
304
-
305
- #[test]
306
- fn test_scope_manager_default() {
307
- let sm = ScopeManager::default();
308
- assert_eq!(sm.current_scope().id, ScopeId(0));
309
- assert!(matches!(sm.current_scope().kind, ScopeKind::TopLevel));
310
- }
311
-
312
- #[test]
313
- fn test_scope_manager_creation() {
314
- let sm = ScopeManager::new();
315
- assert_eq!(sm.current_scope().id, ScopeId(0));
316
- assert!(matches!(sm.current_scope().kind, ScopeKind::TopLevel));
317
- }
318
-
319
- #[test]
320
- fn test_scope_manager_new_scope() {
321
- let mut sm = ScopeManager::new();
322
-
323
- let class_id = sm.new_scope(ScopeKind::Class {
324
- name: "User".to_string(),
325
- superclass: None,
326
- });
327
-
328
- assert_eq!(class_id, ScopeId(1));
329
- assert_eq!(sm.current_scope().id, ScopeId(0)); // Still in top-level
330
- }
331
-
332
- #[test]
333
- fn test_scope_manager_enter_exit() {
334
- let mut sm = ScopeManager::new();
335
-
336
- let class_id = sm.new_scope(ScopeKind::Class {
337
- name: "User".to_string(),
338
- superclass: None,
339
- });
340
-
341
- sm.enter_scope(class_id);
342
- assert_eq!(sm.current_scope().id, ScopeId(1));
343
-
344
- sm.exit_scope();
345
- assert_eq!(sm.current_scope().id, ScopeId(0));
346
- }
347
-
348
- #[test]
349
- fn test_scope_manager_local_var() {
350
- let mut sm = ScopeManager::new();
351
-
352
- sm.current_scope_mut()
353
- .set_local_var("x".to_string(), VertexId(10));
354
-
355
- assert_eq!(sm.lookup_var("x"), Some(VertexId(10)));
356
- assert_eq!(sm.lookup_var("y"), None);
357
- }
358
-
359
- #[test]
360
- fn test_scope_manager_nested_lookup() {
361
- let mut sm = ScopeManager::new();
362
-
363
- // Top level: x = 10
364
- sm.current_scope_mut()
365
- .set_local_var("x".to_string(), VertexId(10));
366
-
367
- // Enter class
368
- let class_id = sm.new_scope(ScopeKind::Class {
369
- name: "User".to_string(),
370
- superclass: None,
371
- });
372
- sm.enter_scope(class_id);
373
-
374
- // Class level: y = 20
375
- sm.current_scope_mut()
376
- .set_local_var("y".to_string(), VertexId(20));
377
-
378
- // Can lookup both x (from parent) and y (from current)
379
- assert_eq!(sm.lookup_var("x"), Some(VertexId(10)));
380
- assert_eq!(sm.lookup_var("y"), Some(VertexId(20)));
381
- }
382
-
383
- #[test]
384
- fn test_scope_manager_current_class_name() {
385
- let mut sm = ScopeManager::new();
386
-
387
- assert_eq!(sm.current_class_name(), None);
388
-
389
- let class_id = sm.new_scope(ScopeKind::Class {
390
- name: "User".to_string(),
391
- superclass: None,
392
- });
393
- sm.enter_scope(class_id);
394
-
395
- assert_eq!(sm.current_class_name(), Some("User".to_string()));
396
-
397
- // Enter method within class
398
- let method_id = sm.new_scope(ScopeKind::Method {
399
- name: "test".to_string(),
400
- receiver_type: None,
401
- return_vertex: None,
402
- });
403
- sm.enter_scope(method_id);
404
-
405
- // Should still find parent class name
406
- assert_eq!(sm.current_class_name(), Some("User".to_string()));
407
- }
408
-
409
- #[test]
410
- fn test_scope_manager_module_scope() {
411
- let mut sm = ScopeManager::new();
412
-
413
- assert_eq!(sm.current_module_name(), None);
414
-
415
- let module_id = sm.new_scope(ScopeKind::Module {
416
- name: "Utils".to_string(),
417
- });
418
- sm.enter_scope(module_id);
419
-
420
- assert_eq!(sm.current_module_name(), Some("Utils".to_string()));
421
-
422
- // Enter method within module
423
- let method_id = sm.new_scope(ScopeKind::Method {
424
- name: "helper".to_string(),
425
- receiver_type: Some("Utils".to_string()),
426
- return_vertex: None,
427
- });
428
- sm.enter_scope(method_id);
429
-
430
- // Should still find parent module name
431
- assert_eq!(sm.current_module_name(), Some("Utils".to_string()));
432
-
433
- sm.exit_scope(); // exit method
434
- sm.exit_scope(); // exit module
435
-
436
- assert_eq!(sm.current_module_name(), None);
437
- }
438
-
439
- #[test]
440
- fn test_scope_manager_module_instance_var() {
441
- let mut sm = ScopeManager::new();
442
-
443
- let module_id = sm.new_scope(ScopeKind::Module {
444
- name: "Config".to_string(),
445
- });
446
- sm.enter_scope(module_id);
447
-
448
- // Set instance variable in module
449
- sm.set_instance_var_in_module("@setting".to_string(), VertexId(100));
450
-
451
- // Enter method within module
452
- let method_id = sm.new_scope(ScopeKind::Method {
453
- name: "get_setting".to_string(),
454
- receiver_type: Some("Config".to_string()),
455
- return_vertex: None,
456
- });
457
- sm.enter_scope(method_id);
458
-
459
- // Should find instance variable from module scope
460
- assert_eq!(
461
- sm.lookup_instance_var_in_module("@setting"),
462
- Some(VertexId(100))
463
- );
464
- }
465
-
466
- #[test]
467
- fn test_current_qualified_name_simple_class() {
468
- let mut sm = ScopeManager::new();
469
-
470
- // module Api; class User; end; end
471
- let class_id = sm.new_scope(ScopeKind::Class {
472
- name: "User".to_string(),
473
- superclass: None,
474
- });
475
- sm.enter_scope(class_id);
476
-
477
- assert_eq!(
478
- sm.current_qualified_name(),
479
- Some("User".to_string())
480
- );
481
- }
482
-
483
- #[test]
484
- fn test_current_qualified_name_nested_module_class() {
485
- let mut sm = ScopeManager::new();
486
-
487
- // module Api
488
- let api_id = sm.new_scope(ScopeKind::Module {
489
- name: "Api".to_string(),
490
- });
491
- sm.enter_scope(api_id);
492
-
493
- // module V1
494
- let v1_id = sm.new_scope(ScopeKind::Module {
495
- name: "V1".to_string(),
496
- });
497
- sm.enter_scope(v1_id);
498
-
499
- // class User
500
- let user_id = sm.new_scope(ScopeKind::Class {
501
- name: "User".to_string(),
502
- superclass: None,
503
- });
504
- sm.enter_scope(user_id);
505
-
506
- assert_eq!(
507
- sm.current_qualified_name(),
508
- Some("Api::V1::User".to_string())
509
- );
510
-
511
- // def greet
512
- let method_id = sm.new_scope(ScopeKind::Method {
513
- name: "greet".to_string(),
514
- receiver_type: None,
515
- return_vertex: None,
516
- });
517
- sm.enter_scope(method_id);
518
-
519
- // Inside method, should still get the qualified class name
520
- assert_eq!(
521
- sm.current_qualified_name(),
522
- Some("Api::V1::User".to_string())
523
- );
524
- }
525
-
526
- #[test]
527
- fn test_current_qualified_name_with_inline_qualified_class() {
528
- let mut sm = ScopeManager::new();
529
-
530
- // class Api::User (defined at top level with qualified name)
531
- let class_id = sm.new_scope(ScopeKind::Class {
532
- name: "Api::User".to_string(),
533
- superclass: None,
534
- });
535
- sm.enter_scope(class_id);
536
-
537
- assert_eq!(
538
- sm.current_qualified_name(),
539
- Some("Api::User".to_string())
540
- );
541
- }
542
-
543
- #[test]
544
- fn test_current_qualified_name_at_top_level() {
545
- let sm = ScopeManager::new();
546
-
547
- // At top level, no class/module
548
- assert_eq!(sm.current_qualified_name(), None);
549
- }
550
-
551
- #[test]
552
- fn test_constant_registration_and_lookup() {
553
- let mut sm = ScopeManager::new();
554
-
555
- // module Api
556
- sm.current_scope_mut().constants.insert("Api".to_string(), "Api".to_string());
557
- let api_id = sm.new_scope(ScopeKind::Module { name: "Api".to_string() });
558
- sm.enter_scope(api_id);
559
-
560
- // class User (inside Api) — register in parent scope (Api)
561
- sm.current_scope_mut().constants.insert("User".to_string(), "Api::User".to_string());
562
- let user_id = sm.new_scope(ScopeKind::Class {
563
- name: "User".to_string(),
564
- superclass: None,
565
- });
566
- sm.enter_scope(user_id);
567
-
568
- assert_eq!(sm.lookup_constant("User"), Some("Api::User".to_string()));
569
- assert_eq!(sm.lookup_constant("Api"), Some("Api".to_string()));
570
- assert_eq!(sm.lookup_constant("Unknown"), None);
571
- }
572
-
573
- #[test]
574
- fn test_constant_lookup_from_method_scope() {
575
- let mut sm = ScopeManager::new();
576
-
577
- sm.current_scope_mut().constants.insert("Api".to_string(), "Api".to_string());
578
- let api_id = sm.new_scope(ScopeKind::Module { name: "Api".to_string() });
579
- sm.enter_scope(api_id);
580
-
581
- sm.current_scope_mut().constants.insert("User".to_string(), "Api::User".to_string());
582
- let user_id = sm.new_scope(ScopeKind::Class {
583
- name: "User".to_string(),
584
- superclass: None,
585
- });
586
- sm.enter_scope(user_id);
587
-
588
- let method_id = sm.new_scope(ScopeKind::Method {
589
- name: "greet".to_string(),
590
- receiver_type: None,
591
- return_vertex: None,
592
- });
593
- sm.enter_scope(method_id);
594
-
595
- // Should find constant by traversing parent scopes from method scope
596
- assert_eq!(sm.lookup_constant("User"), Some("Api::User".to_string()));
597
- }
598
-
599
- #[test]
600
- fn test_constant_same_name_different_namespaces() {
601
- let mut sm = ScopeManager::new();
602
-
603
- // module Api
604
- let api_id = sm.new_scope(ScopeKind::Module { name: "Api".to_string() });
605
- sm.enter_scope(api_id);
606
- sm.current_scope_mut().constants.insert("User".to_string(), "Api::User".to_string());
607
-
608
- sm.exit_scope();
609
-
610
- // module Admin
611
- let admin_id = sm.new_scope(ScopeKind::Module { name: "Admin".to_string() });
612
- sm.enter_scope(admin_id);
613
- sm.current_scope_mut().constants.insert("User".to_string(), "Admin::User".to_string());
614
-
615
- // Inside Admin scope, User should resolve to Admin::User
616
- assert_eq!(sm.lookup_constant("User"), Some("Admin::User".to_string()));
617
- }
618
-
619
- #[test]
620
- fn test_current_method_name() {
621
- let mut sm = ScopeManager::new();
622
- let class_id = sm.new_scope(ScopeKind::Class {
623
- name: "User".to_string(),
624
- superclass: None,
625
- });
626
- sm.enter_scope(class_id);
627
- let method_id = sm.new_scope(ScopeKind::Method {
628
- name: "greet".to_string(),
629
- receiver_type: None,
630
- return_vertex: None,
631
- });
632
- sm.enter_scope(method_id);
633
- assert_eq!(sm.current_method_name(), Some("greet".to_string()));
634
-
635
- sm.exit_scope();
636
- assert_eq!(sm.current_method_name(), None);
637
- }
638
-
639
- #[test]
640
- fn test_current_superclass() {
641
- let mut sm = ScopeManager::new();
642
- let class_id = sm.new_scope(ScopeKind::Class {
643
- name: "Dog".to_string(),
644
- superclass: Some("Animal".to_string()),
645
- });
646
- sm.enter_scope(class_id);
647
- assert_eq!(sm.current_superclass(), Some("Animal".to_string()));
648
-
649
- sm.exit_scope();
650
- assert_eq!(sm.current_superclass(), None);
651
- }
652
-
653
- #[test]
654
- fn test_current_method_name_from_nested_block() {
655
- let mut sm = ScopeManager::new();
656
- let class_id = sm.new_scope(ScopeKind::Class {
657
- name: "User".to_string(),
658
- superclass: Some("Base".to_string()),
659
- });
660
- sm.enter_scope(class_id);
661
- let method_id = sm.new_scope(ScopeKind::Method {
662
- name: "process".to_string(),
663
- receiver_type: None,
664
- return_vertex: None,
665
- });
666
- sm.enter_scope(method_id);
667
- let block_id = sm.new_scope(ScopeKind::Block);
668
- sm.enter_scope(block_id);
669
-
670
- // Inside a block, should still find enclosing method/superclass
671
- assert_eq!(sm.current_method_name(), Some("process".to_string()));
672
- assert_eq!(sm.current_superclass(), Some("Base".to_string()));
673
- }
674
- }
@@ -119,76 +119,3 @@ impl VertexManager {
119
119
  lines.join("\n")
120
120
  }
121
121
  }
122
-
123
- #[cfg(test)]
124
- mod tests {
125
- use super::*;
126
-
127
- #[test]
128
- fn test_new_vertex() {
129
- let mut manager = VertexManager::new();
130
-
131
- let v1 = manager.new_vertex();
132
- let v2 = manager.new_vertex();
133
-
134
- assert_eq!(v1.0, 0);
135
- assert_eq!(v2.0, 1);
136
- assert!(manager.get_vertex(v1).is_some());
137
- assert!(manager.get_vertex(v2).is_some());
138
- }
139
-
140
- #[test]
141
- fn test_new_source() {
142
- let mut manager = VertexManager::new();
143
-
144
- let s1 = manager.new_source(Type::string());
145
- let s2 = manager.new_source(Type::integer());
146
-
147
- assert_eq!(manager.get_source(s1).unwrap().ty.show(), "String");
148
- assert_eq!(manager.get_source(s2).unwrap().ty.show(), "Integer");
149
- }
150
-
151
- #[test]
152
- fn test_edge_propagation() {
153
- let mut manager = VertexManager::new();
154
-
155
- let src = manager.new_source(Type::string());
156
- let vtx = manager.new_vertex();
157
-
158
- manager.add_edge(src, vtx);
159
-
160
- assert_eq!(manager.get_vertex(vtx).unwrap().show(), "String");
161
- }
162
-
163
- #[test]
164
- fn test_chain_propagation() {
165
- let mut manager = VertexManager::new();
166
-
167
- let src = manager.new_source(Type::string());
168
- let v1 = manager.new_vertex();
169
- let v2 = manager.new_vertex();
170
-
171
- manager.add_edge(src, v1);
172
- manager.add_edge(v1, v2);
173
-
174
- assert_eq!(manager.get_vertex(v1).unwrap().show(), "String");
175
- assert_eq!(manager.get_vertex(v2).unwrap().show(), "String");
176
- }
177
-
178
- #[test]
179
- fn test_union_propagation() {
180
- let mut manager = VertexManager::new();
181
-
182
- let src1 = manager.new_source(Type::string());
183
- let src2 = manager.new_source(Type::integer());
184
- let vtx = manager.new_vertex();
185
-
186
- manager.add_edge(src1, vtx);
187
- manager.add_edge(src2, vtx);
188
-
189
- assert_eq!(
190
- manager.get_vertex(vtx).unwrap().show(),
191
- "(Integer | String)"
192
- );
193
- }
194
- }