1
+ package ast
2
+
3
+ import (
4
+ "testing"
5
+ )
6
+
7
+ func TestGetElementOrPropertyAccessName (t * testing.T ) {
8
+ factory := NewNodeFactory (NodeFactoryHooks {})
9
+
10
+ // Test with a string literal argument
11
+ stringLiteral := factory .NewStringLiteral ("key" )
12
+ expression := factory .NewIdentifier ("obj" )
13
+ elementAccess := factory .NewElementAccessExpression (expression , nil , stringLiteral , 0 )
14
+
15
+ name := GetElementOrPropertyAccessName (elementAccess )
16
+ if name != "key" {
17
+ t .Errorf ("Expected GetElementOrPropertyAccessName to return 'key', got '%s'" , name )
18
+ }
19
+
20
+ // Test with a numeric literal argument
21
+ numericLiteral := factory .NewNumericLiteral ("123" )
22
+ elementAccess = factory .NewElementAccessExpression (expression , nil , numericLiteral , 0 )
23
+
24
+ name = GetElementOrPropertyAccessName (elementAccess )
25
+ if name != "123" {
26
+ t .Errorf ("Expected GetElementOrPropertyAccessName to return '123', got '%s'" , name )
27
+ }
28
+
29
+ // Test with a non-literal argument
30
+ nonLiteralArg := factory .NewIdentifier ("nonLiteralKey" )
31
+ elementAccess = factory .NewElementAccessExpression (expression , nil , nonLiteralArg , 0 )
32
+
33
+ name = GetElementOrPropertyAccessName (elementAccess )
34
+ if name != "" {
35
+ t .Errorf ("Expected GetElementOrPropertyAccessName to return '', got '%s'" , name )
36
+ }
37
+ }
0 commit comments