1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 03:50:08 +02:00

Correctly parse .valetrc files

This commit is contained in:
2023-01-24 19:47:28 +01:00
parent 7936d14440
commit 25f824defd
7 changed files with 127 additions and 26 deletions

View File

@ -12,19 +12,39 @@ class ValetRcTest: XCTestCase {
// MARK: - Test Files
static var path: URL {
static var validPath: URL {
return Bundle(for: Self.self)
.url(forResource: "valetrc", withExtension: "rc")!
.url(forResource: "valetrc", withExtension: "valid")!
}
static var brokenPath: URL {
return Bundle(for: Self.self)
.url(forResource: "valetrc", withExtension: "broken")!
}
// MARK: - Tests
func test_can_extract_fields_from_valetrc_file() throws {
// TODO: Load the path and get the fields
}
let fakeFile = RCFile.fromPath("/Users/fake/file.rc")
XCTAssertNil(fakeFile)
func test_skip_invalid_fields_valetrc_file() throws {
// TODO: Load the path and throw error
}
// Can parse the file
let validFile = RCFile.fromPath(ValetRcTest.validPath.path)
XCTAssertNotNil(validFile)
let fields = validFile!.fields
// Correctly parses and trims (and omits double quotes) per line
XCTAssertEqual(fields["PHP"], "php@8.2")
XCTAssertEqual(fields["OTHER"], "thing")
XCTAssertEqual(fields["PHPMON_WATCH"], "true")
XCTAssertEqual(fields["SYNTAX"], "variable")
// Ignores entries prefixed with #
XCTAssertTrue(!fields.keys.contains("#PHP"))
// Ignores invalid lines
XCTAssertTrue(!fields.keys.contains("OOF"))
}
}

View File

@ -1,3 +0,0 @@
PHP=php@8.2
OTHER=thing
PHPMON_WATCH=true

View File

@ -0,0 +1,6 @@
PHP=php@8.2
#PHP=php
OTHER=thing
PHPMON_WATCH=true
SYNTAX = "variable"
OOF:NICE