Skip to content

Commit

Permalink
Add missing C++ tests (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
gandarez committed Aug 18, 2023
1 parent e6de3d1 commit 49b5f8e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
34 changes: 32 additions & 2 deletions lexers/cpp_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
package lexers_test

import (
"os"
"testing"

assert "github.com/alecthomas/assert/v2"

"github.com/alecthomas/chroma/v2"
"github.com/alecthomas/chroma/v2/lexers"

"github.com/alecthomas/assert/v2"
)

func TestCpp_AnalyseText(t *testing.T) {
tests := map[string]struct {
Filepath string
Expected float32
}{
"include": {
Filepath: "testdata/cpp_include.cpp",
Expected: 0.2,
},
"namespace": {
Filepath: "testdata/cpp_namespace.cpp",
Expected: 0.4,
},
}

for name, test := range tests {
test := test
t.Run(name, func(t *testing.T) {
data, err := os.ReadFile(test.Filepath)
assert.NoError(t, err)

analyser, ok := lexers.CPP.(chroma.Analyser)
assert.True(t, ok)

assert.Equal(t, test.Expected, analyser.AnalyseText(string(data)))
})
}
}

func TestIssue290(t *testing.T) {
input := `// 64-bit floats have 53 digits of precision, including the whole-number-part.
double a = 0011111110111001100110011001100110011001100110011001100110011010; // imperfect representation of 0.1
Expand Down
1 change: 1 addition & 0 deletions lexers/testdata/cpp_include.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <iostream>
1 change: 1 addition & 0 deletions lexers/testdata/cpp_namespace.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
using namespace std;

0 comments on commit 49b5f8e

Please sign in to comment.