From 846a27fe7c6863e9e488762323b1d6502be83be6 Mon Sep 17 00:00:00 2001
From: Nipuna Fernando <nipunafe@gmail.com>
Date: Mon, 6 Nov 2023 09:57:16 +0530
Subject: [PATCH] Add typeof tests for resource segments

---
 .../TypeOfInResourceAccessActionTest.java     | 10 ++++++++
 .../actions/resource_access_action.bal        | 24 +++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/typeof/TypeOfInResourceAccessActionTest.java b/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/typeof/TypeOfInResourceAccessActionTest.java
index ff174ba97f77..290c53455b73 100644
--- a/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/typeof/TypeOfInResourceAccessActionTest.java
+++ b/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/typeof/TypeOfInResourceAccessActionTest.java
@@ -30,6 +30,8 @@
 
 import java.util.Optional;
 
+import static io.ballerina.compiler.api.symbols.TypeDescKind.INT;
+import static io.ballerina.compiler.api.symbols.TypeDescKind.STRING;
 import static io.ballerina.compiler.api.symbols.TypeDescKind.TYPE_REFERENCE;
 import static io.ballerina.compiler.api.symbols.TypeDescKind.UNION;
 import static org.testng.Assert.assertEquals;
@@ -60,6 +62,14 @@ public Object[][] getPos() {
         return new Object[][]{
                 {42, 23, 42, 54, UNION},
                 {42, 23, 42, 32, TYPE_REFERENCE},
+                {110, 9, 110, 12, STRING},
+                {111, 9, 111, 14, STRING},
+                {111, 17, 111, 25, STRING},
+                {112, 17, 111, 19, STRING},
+                {113, 15, 113, 19, INT},
+                {114, 15, 114, 16, INT},
+                {115, 9, 115, 14, STRING},
+                {115, 17, 115, 24, STRING},
         };
     }
 
diff --git a/tests/ballerina-compiler-api-test/src/test/resources/test-src/actions/resource_access_action.bal b/tests/ballerina-compiler-api-test/src/test/resources/test-src/actions/resource_access_action.bal
index 8ced189ea6a6..2af9eb311b0c 100644
--- a/tests/ballerina-compiler-api-test/src/test/resources/test-src/actions/resource_access_action.bal
+++ b/tests/ballerina-compiler-api-test/src/test/resources/test-src/actions/resource_access_action.bal
@@ -91,3 +91,27 @@ public function testPathSegmentOfAmbiguousResourceFunction() {
    Bam bam = new;
    bam->/path1/path2.post();
 }
+
+client class Resc {
+    resource function post user() {}
+
+    resource function post [string name]() {}
+
+    resource function get sports/[string name]() {}
+
+    resource function get pets/[int id]() {}
+
+    resource function get sports/[string name]/info () {}
+}
+
+function testTypeOfResourceSegments() {
+    Resc cl = new;
+    string myString = "";
+    int myInt = 0;
+    cl->/user.post();
+    cl->/sports/[myString]();
+    cl->/sports/["A"]();
+    cl->/pets/[myInt]();
+    cl->/pets/[1]();
+    cl->/sports/[myString]/
+}