Skip to content

Commit

Permalink
test: add generic testing framework
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Jul 4, 2024
1 parent 02eefe5 commit 1ac390a
Show file tree
Hide file tree
Showing 7 changed files with 373 additions and 182 deletions.
18 changes: 17 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,21 @@ if-statement spans multiple lines.
A pull request for supporting a new language requires:

1. Adding `queries/[LANG]/context.scm` as explained in the previous section.
2. Adding `test/test.[LANG EXT]` with code examples the `context.scm` is designed to support.

2. Adding `test/lang/test.[LANG]` or `test/lang/test.[LANG].[EXT]` with code examples the `context.scm` is designed to support.
- These test files use custom comment directives to annotate what lines should be a context. It has the format.

```c
// {{TEST}} -- mark start of test

int main() { // {{CONTEXT}} -- mark line as a context


// {{CURSOR}} -- where cursor needs to be for contexts to be shown.

}
```

See `test/lang/test.c` for examples.

3. Updating `README.md` to mark `[LANG]` as supported.
87 changes: 35 additions & 52 deletions test/lang/test.bash
Original file line number Diff line number Diff line change
@@ -1,96 +1,79 @@
#!/bin/bash
foo() {

if [ 1 -eq 1 ]; then
echo 1




# {{TEST}}

foo() { # {{CONTEXT}}

if [ 1 -eq 1 ]; then # {{CONTEXT}}
echo 1


# {{CURSOR}}
fi

case "$i" in
1) echo 1

}


# {{TEST}}

bar() { # {{CONTEXT}}
case "$i" in # {{CONTEXT}}
1) echo 1 # {{CONTEXT}}



# {{CURSOR}}
;;
2|3) echo 2 or 3
;;
*) echo default
;;
esac
}


while [ $x -le 5 ]
# {{TEST}}

baz() { # {{CONTEXT}}
while [ $x -le 5 ] # {{CONTEXT}}
do
echo "Welcome $x times"





x=$(( $x + 1 ))
# {{CURSOR}}
done
}

# {{TEST}}

baz2() { # {{CONTEXT}}
# until is also a while loop
until [ $x -gt 5 ]
until [ $x -gt 5 ] # {{CONTEXT}}
do
echo Counter: $x






((x++))
# {{CURSOR}}
done

# select is a for statement
select character in Sheldon Leonard Penny Howard Raj
do
echo "Selected character: $character"





echo "Selected number: $REPLY"
done

for ((i=0; i<=10000; i++)); do







echo "$i"
done


}

# {{TEST}}

# select is a for statement
select character in Sheldon Leonard Penny Howard Raj # {{CONTEXT}}
do
echo "Selected character: $character"

# {{CURSOR}}
done

# {{POPCONTEXT}}

for ((i=0; i<=10000; i++)); do # {{CONTEXT}}








# {{CURSOR}}
echo "$i"
done


180 changes: 61 additions & 119 deletions test/lang/test.c
Original file line number Diff line number Diff line change
@@ -1,148 +1,90 @@
struct Bert {
// {{TEST}}

struct Bert { // {{CONTEXT}}
int *f1;
// comment
int *f2;
// comment
// comment
// comment
// comment
// comment

// {{CURSOR}}
};

typedef enum {

// {{TEST}}

typedef enum { // {{CONTEXT}}
E1,
E2,
E3
// comment
// comment
// comment
// comment
// comment
// comment
// {{CURSOR}}
} Myenum;

int main(int arg1,

// {{TEST}}

int main(int arg1, // {{CONTEXT}}
char **arg2,
char **arg3
)
char **arg3)
{

if (arg1 == 4
if (arg1 == 4 // {{CONTEXT}}
&& arg2 == arg3) {

// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
for (int i = 0; i < arg1; i++) {
// comment
// comment
// comment
// comment
while (1) {
// comment
// comment
// comment
// comment
// comment
// {{CURSOR}}

for (int i = 0; i < arg1; i++) { // {{CONTEXT}}

// {{CURSOR}}
while (1) { // {{CONTEXT}}


// {{CURSOR}}
}

do {
// comment
// comment
// comment
// comment
// comment
}
}
}


// {{TEST}}

void foo(int a) { // {{CONTEXT}}
if (a) { // {{CONTEXT}}
do { // {{CONTEXT}}



// {{CURSOR}}
} while (1);
// comment
// comment
// comment
// comment
// comment
}
}
}

} else if (arg1 == 4) {
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment

} else {
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// {{TEST}}

void bar(int a) { // {{CONTEXT}}
if (a) { // {{CONTEXT}}

} else if (a == 4) { // {{CONTEXT}}
// comment
} else { // {{CONTEXT}}



// {{CURSOR}}
}
}

switch (arg1) {
// comment
// comment

// {{TEST}}

void baz(int a) { // {{CONTEXT}}
switch (a) { // {{CONTEXT}}
case 0:
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
break;
case 1: {
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
// comment
case 1: { // {{CONTEXT}}



// {{CURSOR}}
} break;
}
}
13 changes: 13 additions & 0 deletions test/lang/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- {{TEST}}

local function foo() -- {{CONTEXT}}

local function bar() -- {{CONTEXT}}



-- {{CURSOR}}

end

end
Loading

0 comments on commit 1ac390a

Please sign in to comment.