summary refs log tree commit diff stats
path: root/svc
diff options
context:
space:
mode:
Diffstat (limited to 'svc')
-rw-r--r--svc/query_test.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/svc/query_test.go b/svc/query_test.go
index 9fe6496..687b102 100644
--- a/svc/query_test.go
+++ b/svc/query_test.go
@@ -9,6 +9,36 @@ import (
 	"github.com/getwtxt/registry"
 )
 
+func Test_dedupe(t *testing.T) {
+	t.Run("Simple Deduplication Test", func(t *testing.T) {
+		start := []string{
+			"first",
+			"second",
+			"third",
+			"third",
+		}
+		finish := dedupe(start)
+		if reflect.DeepEqual(start, finish) {
+			t.Errorf("Deduplication didn't occur\n")
+		}
+		if len(finish) != 3 {
+			t.Errorf("Ending length not what was expected\n")
+		}
+	})
+}
+
+func Benchmark_dedupe(b *testing.B) {
+	start := []string{
+		"first",
+		"second",
+		"third",
+		"third",
+	}
+	for i := 0; i < b.N; i++ {
+		dedupe(start)
+	}
+}
+
 func Test_parseQueryOut(t *testing.T) {
 	initTestConf()
 
@@ -71,7 +101,53 @@ func Benchmark_parseQueryOut(b *testing.B) {
 	for i := 0; i < b.N; i++ {
 		parseQueryOut(data)
 	}
+}
 
+func Test_joinQueryOuts(t *testing.T) {
+	first := []string{
+		"one",
+		"two",
+		"three",
+	}
+	second := []string{
+		"three",
+		"four",
+		"five",
+		"six",
+	}
+	t.Run("Joining two string slices", func(t *testing.T) {
+		third := joinQueryOuts(first, second)
+		if len(third) != (len(first) + len(second) - 1) {
+			t.Errorf("Was not combined or deduplicated properly\n")
+		}
+		fourth := make([]string, 6)
+		for i := 0; i < len(first); i++ {
+			fourth[i] = first[i]
+		}
+		for i := 1; i < len(second); i++ {
+			fourth[2+i] = second[i]
+		}
+		if !reflect.DeepEqual(fourth, third) {
+			t.Errorf("Output not deeply equal to manual construction\n")
+		}
+	})
+}
+
+func Benchmark_joinQueryOuts(b *testing.B) {
+	first := []string{
+		"one",
+		"two",
+		"three",
+	}
+	second := []string{
+		"three",
+		"four",
+		"five",
+		"six",
+	}
+	for i := 0; i < b.N; i++ {
+		joinQueryOuts(first, second)
+	}
 }
 
 func Test_compositeStatusQuery(t *testing.T) {
new Vim convenience macro' href='/akkartik/mu/commit/subx/run_one_test.sh?h=main&id=5ac0786623f5ebd0b3a4f23fb6c23b72e6e277cb'>5ac07866 ^
01b6cfe4 ^
ab107e18 ^
0bcfe6e5 ^
d260b017 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
                  
                                                                               
                                                                      

                                                                              


                       
                                                                                 
                                                              

                                   
    
                                  
    


                            
 
      
 
                                                                       

                                            
#!/usr/bin/env zsh
# Either run the test with the given name, or rerun the most recently run test.
# Intended to be called from within Vim. Check out the vimrc.vim file.
# Unfortunately this only works with Linux at the moment. Some compiler passes
# take too long to run in emulated mode.

if [[ $2 == 'test-'* ]]
then
  TEST_NAME=$2 envsubst '$TEST_NAME' < run_one_test.subx > /tmp/run_one_test.subx
  FILES=$(ls [0-9]*.subx apps/subx-params.subx $1 |sort |uniq)
  echo $FILES > /tmp/last_run_files
elif [[ -e /tmp/last_run_files ]]
then
  FILES=$(cat /tmp/last_run_files)
else
  echo "no test found"
  exit 0  # don't open trace
fi

set -e

./translate_subx_debug init.linux $(echo $FILES) /tmp/run_one_test.subx
echo running
CFLAGS=$CFLAGS ./bootstrap --trace run a.elf