Skip to content

Commit

Permalink
improvements to parse_builtins and test2
Browse files Browse the repository at this point in the history
  • Loading branch information
refaktor committed Nov 18, 2024
1 parent 4c97005 commit 430cd54
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 301 deletions.
40 changes: 32 additions & 8 deletions cmd/parse_builtins/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ func getCommentsAboveKey(fset *token.FileSet, comments []*ast.CommentGroup, keyP
// Helper function to get comments above the map key
func parseCommentsAboveKey(input string, info *builtinInfo) builtinInfo {

const (
inDoc = iota
inTests
inExamples
inArgs
)
position := inDoc

// info := builtinInfo{}

// Step 1: Split input into lines and trim whitespace
Expand All @@ -53,25 +61,34 @@ func parseCommentsAboveKey(input string, info *builtinInfo) builtinInfo {
// Step 2: Separate header and tests
var headerLines []string
// var testLines []string
isTestSection := false

// fmt.Println("!!!!!!!!!!!!!!!**************")

for _, line := range lines {
line = strings.TrimSpace(line) // Remove leading and trailing whitespace
// fmt.Println("LLLL:" + line)
// fmt.Println(line)
if line == "Tests:" {
// fmt.Println("***** TEST ****")
isTestSection = true
switch line {
case "Tests:":
position = inTests
continue
case "Examples:":
position = inExamples
continue
case "Args:":
position = inArgs
continue
}

if isTestSection {
// fmt.Println(line)
switch position {
case inTests:
info.tests = append(info.tests, line)
} else {
case inDoc:
headerLines = append(headerLines, line)
case inExamples:
info.examples = append(info.examples, line) // TODO --- examples can be multiline, there is a name also
case inArgs:
info.args = append(info.args, line)
}
}
// Step 3: Combine the header lines into a single string
Expand All @@ -85,7 +102,14 @@ func outputInfo(infos []builtinInfo) {
if len(info.tests) > 0 {
fmt.Printf("\tgroup %s \n", info.name) // name
fmt.Printf("\t\"%s\"\n", info.docstring) // docstring
fmt.Print("\t{ }\n\t{\n") // args

fmt.Print("\t{\n") // args
for _, t := range info.args {
fmt.Println("\t\targ \"" + t + "\"")
}
fmt.Println("\t}\n")

fmt.Print("\t{\n")
for _, t := range info.tests {
fmt.Println("\t\t" + t)
}
Expand Down
22 changes: 18 additions & 4 deletions evaldo/builtins_spreadsheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
var Builtins_spreadsheet = map[string]*env.Builtin{

// Tests:
// equals { spreadsheet { "a" } { 1 2 } |type? } 'spreadsheet
// equal { spreadsheet { "a" } { 1 2 } |type? } 'spreadsheet
// Args:
// * columns
// * data
Expand Down Expand Up @@ -81,7 +81,7 @@ var Builtins_spreadsheet = map[string]*env.Builtin{
},

// Tests:
// equals { to-spreadsheet dict { "a" 1 "a" b } |type? } 'spreadsheet
// equal { to-spreadsheet list [ dict { "a" 1 } dict { "a" b } ] |type? } 'spreadsheet
// Args:
// * data
"to-spreadsheet": {
Expand Down Expand Up @@ -138,6 +138,10 @@ var Builtins_spreadsheet = map[string]*env.Builtin{
for key := range dict {
k[key] = struct{}{}
}
case env.Dict:
for key := range dict.Data {
k[key] = struct{}{}
}
default:
return MakeBuiltinError(ps, "List must contain only dicts", "to-spreadsheet")
}
Expand All @@ -158,8 +162,18 @@ var Builtins_spreadsheet = map[string]*env.Builtin{
}
row[i] = data
}
spr.AddRow(*env.NewSpreadsheetRow(row, spr))
case env.Dict:
row := make([]any, len(keys))
for i, key := range keys {
data, ok := dict.Data[key]
if !ok {
data = env.Void{}
}
row[i] = data
}
spr.AddRow(*env.NewSpreadsheetRow(row, spr))
}
spr.AddRow(*env.NewSpreadsheetRow(row, spr))
}
return *spr

Expand Down Expand Up @@ -194,7 +208,7 @@ var Builtins_spreadsheet = map[string]*env.Builtin{
// 2) A native that is a slice of SpreadsheetRows, like the value returned from `get-rows`
// Tests:
// equal {
// ref spreadsheet { "a" "b" } { 1 10 2 20 } :sheet
// ref spreadsheet { "a" "b" } { 1 10 2 20 } ::sheet
// sheet .add-rows! [ 3 30 ] sheet .deref .length?
// } 3
// Args:
Expand Down
204 changes: 0 additions & 204 deletions tests2/base.rye

This file was deleted.

8 changes: 4 additions & 4 deletions tests2/main.rye
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test-framework: context {

section: fn { name descr code } { term/magenta term/bold print name term/reset\all print " " + descr , do code print "" }

group: fn { name descr args code } { inc! 'cnt term/blue prns " " + name term/reset\all , do code }
group: fn { name descr args code } { inc! 'cnt term/green prns " " + name term/reset\all , do code }

error-: fn { test } {
; try { do\in root-ctx test }
Expand Down Expand Up @@ -86,12 +86,12 @@ generate-menu: fn { menu } {
generate-doc-file: fn { filename menu } {
join {
%tpl/header.html .read .replace "{{title}}" capitalize filename ; |replace "{{menu}}" generate-menu menu
capture-stdout { do\in docs-framework load to-file filename + ".rye" }
capture-stdout { do\in docs-framework load to-file filename + ".tests.rye" }
read %tpl/footer.html
} |write* to-file filename + ".html"
}

menu: { "base" }
menu: { "base" "spreadsheet" }

print-help: does {
print `# Rye's simple testing tool
Expand Down Expand Up @@ -123,7 +123,7 @@ test {
errors: 0
for sections {
.to-string .pass { term/bold , prns "\n#" , .to-upper .prns , print "#\n" }
|+ ".rye" |to-file |load |^check { "group does not exist!" } |do\in* test-framework |+ errors ::errors }
|+ ".tests.rye" |to-file |load |^check { "group does not exist!" } |do\in* test-framework |+ errors ::errors }
print ""

if ( length? sections ) > 1 {
Expand Down
Loading

0 comments on commit 430cd54

Please sign in to comment.