This commit is contained in:
		
							
								
								
									
										46
									
								
								test/gltoml_test.gleam
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								test/gltoml_test.gleam
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
import gleam/list
 | 
			
		||||
import gleam/string
 | 
			
		||||
import gltoml
 | 
			
		||||
import simplifile
 | 
			
		||||
import startest
 | 
			
		||||
import startest/expect
 | 
			
		||||
 | 
			
		||||
pub fn main() -> Nil {
 | 
			
		||||
  startest.run(startest.default_config())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// gleeunit test functions end in `_test`
 | 
			
		||||
pub fn files_tests() {
 | 
			
		||||
  let assert Ok(test_file) =
 | 
			
		||||
    simplifile.read("./toml-test/tests/files-toml-1.1.0")
 | 
			
		||||
  let files =
 | 
			
		||||
    string.split(test_file, "\n")
 | 
			
		||||
    |> list.filter(fn(filename) { string.ends_with(filename, ".toml") })
 | 
			
		||||
    // We need to omit the encoding tests because these generally require a different method to
 | 
			
		||||
    // load as simplifile doesn't appear to open non-valid utf 8/16 files
 | 
			
		||||
    |> list.filter(fn(filename) {
 | 
			
		||||
      !string.starts_with(filename, "invalid/encoding")
 | 
			
		||||
    })
 | 
			
		||||
  files |> list.length |> echo
 | 
			
		||||
 | 
			
		||||
  list.map(files, fn(filename) {
 | 
			
		||||
    startest.it(filename, fn() {
 | 
			
		||||
      let toml =
 | 
			
		||||
        simplifile.read("./toml-test/tests/" <> filename) |> expect.to_be_ok
 | 
			
		||||
 | 
			
		||||
      let tom = gltoml.parse(toml)
 | 
			
		||||
      case filename {
 | 
			
		||||
        "valid/" <> _ -> {
 | 
			
		||||
          expect.to_be_ok(tom)
 | 
			
		||||
          Nil
 | 
			
		||||
        }
 | 
			
		||||
        "invalid/" <> _ -> {
 | 
			
		||||
          expect.to_be_error(tom)
 | 
			
		||||
          Nil
 | 
			
		||||
        }
 | 
			
		||||
        _ -> Nil
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
  })
 | 
			
		||||
  |> startest.describe("files test", _)
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user