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", _)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										16
									
								
								test/scratch.gleam
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								test/scratch.gleam
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
import gleam/string
 | 
			
		||||
import gleam/time/calendar
 | 
			
		||||
import gltoml
 | 
			
		||||
 | 
			
		||||
pub fn main() {
 | 
			
		||||
  calendar.Date(25, calendar.March, 2025)
 | 
			
		||||
  |> echo
 | 
			
		||||
  |> calendar.is_valid_date
 | 
			
		||||
  |> echo
 | 
			
		||||
  gltoml.parse(
 | 
			
		||||
    //"#hello\n   'a.b' = '1'\nc = true\ng=2025-03-25T10:03:23.500000000+01:00\nh=12308_123\ni=-2\nf = 0o751\nd=0b1_1_0_1\ne=0x1ab_4ef\nj=-nan\nk=1.5e2",
 | 
			
		||||
    // "tab = { inner.table = [{}], inner.table.val = \"bad\" }",
 | 
			
		||||
    "a = {   a.b  =  1   }",
 | 
			
		||||
  )
 | 
			
		||||
  |> echo
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user