mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-19 07:25:27 +02:00
test(sshd_config): Add tests
This commit is contained in:
parent
af580fa624
commit
82a08d6459
@ -114,4 +114,3 @@ func (s *sshParserListener) ExitValue(ctx *parser.ValueContext) {
|
|||||||
|
|
||||||
s.sshContext.currentOption = nil
|
s.sshContext.currentOption = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ func (c *SSHConfig) parseStatement(
|
|||||||
stream := antlr.NewInputStream(input)
|
stream := antlr.NewInputStream(input)
|
||||||
|
|
||||||
lexerErrorListener := createErrorListener(context.line)
|
lexerErrorListener := createErrorListener(context.line)
|
||||||
lexer := parser.NewConfigLexer(&stream)
|
lexer := parser.NewConfigLexer(stream)
|
||||||
lexer.RemoveErrorListeners()
|
lexer.RemoveErrorListeners()
|
||||||
lexer.AddErrorListener(&lexerErrorListener)
|
lexer.AddErrorListener(&lexerErrorListener)
|
||||||
|
|
||||||
@ -83,4 +83,3 @@ func (c *SSHConfig) parseStatement(
|
|||||||
|
|
||||||
return errors
|
return errors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
60
handlers/sshd_config/ast/parser_test.go
Normal file
60
handlers/sshd_config/ast/parser_test.go
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package ast
|
||||||
|
|
||||||
|
import (
|
||||||
|
"config-lsp/utils"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSimpleParserExample(
|
||||||
|
t *testing.T,
|
||||||
|
) {
|
||||||
|
input := utils.Dedent(`
|
||||||
|
PermitRootLogin no
|
||||||
|
PasswordAuthentication yes
|
||||||
|
`)
|
||||||
|
p := NewSSHConfig()
|
||||||
|
errors := p.Parse(input)
|
||||||
|
|
||||||
|
if len(errors) != 0 {
|
||||||
|
t.Fatalf("Expected no errors, got %v", errors)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !(p.Options.Size() == 2 &&
|
||||||
|
len(utils.KeysOfMap(p.CommentLines)) == 0) {
|
||||||
|
t.Errorf("Expected 2 options and no comment lines, but got: %v, %v", p.Options, p.CommentLines)
|
||||||
|
}
|
||||||
|
|
||||||
|
rawFirstEntry, _ := p.Options.Get(uint32(0))
|
||||||
|
firstEntry := rawFirstEntry.(*SSHOption)
|
||||||
|
|
||||||
|
if !(firstEntry.Value == "PermitRootLogin no" &&
|
||||||
|
firstEntry.LocationRange.Start.Line == 0 &&
|
||||||
|
firstEntry.LocationRange.End.Line == 0 &&
|
||||||
|
firstEntry.LocationRange.Start.Character == 0 &&
|
||||||
|
firstEntry.LocationRange.End.Character == 18 &&
|
||||||
|
firstEntry.Key.Value == "PermitRootLogin" &&
|
||||||
|
firstEntry.Key.LocationRange.Start.Character == 0 &&
|
||||||
|
firstEntry.Key.LocationRange.End.Character == 15 &&
|
||||||
|
firstEntry.OptionValue.Value == "no" &&
|
||||||
|
firstEntry.OptionValue.LocationRange.Start.Character == 16 &&
|
||||||
|
firstEntry.OptionValue.LocationRange.End.Character == 18) {
|
||||||
|
t.Errorf("Expected first entry to be PermitRootLogin no, but got: %v", firstEntry)
|
||||||
|
}
|
||||||
|
|
||||||
|
rawSecondEntry, _ := p.Options.Get(uint32(1))
|
||||||
|
secondEntry := rawSecondEntry.(*SSHOption)
|
||||||
|
|
||||||
|
if !(secondEntry.Value == "PasswordAuthentication yes" &&
|
||||||
|
secondEntry.LocationRange.Start.Line == 1 &&
|
||||||
|
secondEntry.LocationRange.End.Line == 1 &&
|
||||||
|
secondEntry.LocationRange.Start.Character == 0 &&
|
||||||
|
secondEntry.LocationRange.End.Character == 26 &&
|
||||||
|
secondEntry.Key.Value == "PasswordAuthentication" &&
|
||||||
|
secondEntry.Key.LocationRange.Start.Character == 0 &&
|
||||||
|
secondEntry.Key.LocationRange.End.Character == 22 &&
|
||||||
|
secondEntry.OptionValue.Value == "yes" &&
|
||||||
|
secondEntry.OptionValue.LocationRange.Start.Character == 23 &&
|
||||||
|
secondEntry.OptionValue.LocationRange.End.Character == 26) {
|
||||||
|
t.Errorf("Expected second entry to be PasswordAuthentication yes, but got: %v", secondEntry)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user