From 15c84b65a3fdfa9452b38e40d355d18abff0df8d Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Sun, 30 Apr 2023 20:14:50 +0530 Subject: [PATCH 1/3] feat: make pkg as WIP --- gnovm/pkg/gnomod/file.go | 1 + gnovm/pkg/gnomod/parse.go | 4 ++++ gnovm/pkg/gnomod/read.go | 12 ++++++++++++ 3 files changed, 17 insertions(+) diff --git a/gnovm/pkg/gnomod/file.go b/gnovm/pkg/gnomod/file.go index 564d4e29361..3289db99c36 100644 --- a/gnovm/pkg/gnomod/file.go +++ b/gnovm/pkg/gnomod/file.go @@ -15,6 +15,7 @@ import ( // Parsed gno.mod file. type File struct { + Wip bool Module *modfile.Module Go *modfile.Go Require []*modfile.Require diff --git a/gnovm/pkg/gnomod/parse.go b/gnovm/pkg/gnomod/parse.go index dfb5ac62057..acb55f0680e 100644 --- a/gnovm/pkg/gnomod/parse.go +++ b/gnovm/pkg/gnomod/parse.go @@ -49,6 +49,10 @@ func Parse(file string, data []byte) (*File, error) { f.add(&errs, x, l, x.Token[0], l.Token) } } + case *modfile.CommentBlock: + if x.Start.Line == 1 { + f.Wip = parseWip(x) + } } } diff --git a/gnovm/pkg/gnomod/read.go b/gnovm/pkg/gnomod/read.go index a05efa19c9f..25ceb1628b0 100644 --- a/gnovm/pkg/gnomod/read.go +++ b/gnovm/pkg/gnomod/read.go @@ -833,3 +833,15 @@ func parseDirectiveComment(block *modfile.LineBlock, line *modfile.Line) string } return strings.Join(lines, "\n") } + +// parseWip returns whether the module is marked as a work in progress. +func parseWip(block *modfile.CommentBlock) bool { + if len(block.Before) != 1 { + return false + } + comment := block.Before[0] + if strings.TrimSpace(strings.TrimPrefix(comment.Token, "//")) != "WIP" { + return false + } + return true +} From 10850fdeb99732ca68facdf44c73df9bf1b2b865 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Sun, 30 Apr 2023 20:25:14 +0530 Subject: [PATCH 2/3] add tests --- gnovm/pkg/gnomod/parse_test.go | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/gnovm/pkg/gnomod/parse_test.go b/gnovm/pkg/gnomod/parse_test.go index ce3a745147e..8f802d33489 100644 --- a/gnovm/pkg/gnomod/parse_test.go +++ b/gnovm/pkg/gnomod/parse_test.go @@ -116,3 +116,54 @@ func TestModuleDeprecated(t *testing.T) { }) } } + +func TestParseWip(t *testing.T) { + for _, tc := range []struct { + desc, in string + expected bool + }{ + { + desc: "no_comment", + in: `module m`, + }, + { + desc: "other_comment", + in: `// yo`, + }, + { + desc: "wip_no_space", + in: `//WIP`, + expected: true, + }, + { + desc: "wip_simple", + in: `// WIP`, + expected: true, + }, + { + desc: "wip_lowercase", + in: `// wip`, + }, + { + desc: "wip_multiline", + in: `// wip + // yo`, + }, + { + desc: "wip_mixed", + in: `// some other comment + // WIP`, + }, + { + desc: "wip_not_first_line", + in: ` + // WIP`, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + f, err := Parse("in", []byte(tc.in)) + assert.Nil(t, err) + assert.Equal(t, tc.expected, f.Wip) + }) + } +} From 13a836f5c3b8190f2b0dfa22a2b05bf06a10db6c Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Wed, 3 May 2023 17:52:51 +0530 Subject: [PATCH 3/3] s/wip/draft --- gnovm/pkg/gnomod/file.go | 2 +- gnovm/pkg/gnomod/parse.go | 2 +- gnovm/pkg/gnomod/parse_test.go | 28 ++++++++++++++-------------- gnovm/pkg/gnomod/read.go | 6 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/gnovm/pkg/gnomod/file.go b/gnovm/pkg/gnomod/file.go index 3289db99c36..473e60850ca 100644 --- a/gnovm/pkg/gnomod/file.go +++ b/gnovm/pkg/gnomod/file.go @@ -15,7 +15,7 @@ import ( // Parsed gno.mod file. type File struct { - Wip bool + Draft bool Module *modfile.Module Go *modfile.Go Require []*modfile.Require diff --git a/gnovm/pkg/gnomod/parse.go b/gnovm/pkg/gnomod/parse.go index acb55f0680e..a23a5a06b46 100644 --- a/gnovm/pkg/gnomod/parse.go +++ b/gnovm/pkg/gnomod/parse.go @@ -51,7 +51,7 @@ func Parse(file string, data []byte) (*File, error) { } case *modfile.CommentBlock: if x.Start.Line == 1 { - f.Wip = parseWip(x) + f.Draft = parseDraft(x) } } } diff --git a/gnovm/pkg/gnomod/parse_test.go b/gnovm/pkg/gnomod/parse_test.go index 8f802d33489..934531e69c7 100644 --- a/gnovm/pkg/gnomod/parse_test.go +++ b/gnovm/pkg/gnomod/parse_test.go @@ -117,7 +117,7 @@ func TestModuleDeprecated(t *testing.T) { } } -func TestParseWip(t *testing.T) { +func TestParseDraft(t *testing.T) { for _, tc := range []struct { desc, in string expected bool @@ -131,39 +131,39 @@ func TestParseWip(t *testing.T) { in: `// yo`, }, { - desc: "wip_no_space", - in: `//WIP`, + desc: "draft_no_space", + in: `//Draft`, expected: true, }, { - desc: "wip_simple", - in: `// WIP`, + desc: "draft_simple", + in: `// Draft`, expected: true, }, { - desc: "wip_lowercase", - in: `// wip`, + desc: "draft_lowercase", + in: `// draft`, }, { - desc: "wip_multiline", - in: `// wip + desc: "draft_multiline", + in: `// Draft // yo`, }, { - desc: "wip_mixed", + desc: "draft_mixed", in: `// some other comment - // WIP`, + // Draft`, }, { - desc: "wip_not_first_line", + desc: "draft_not_first_line", in: ` - // WIP`, + // Draft`, }, } { t.Run(tc.desc, func(t *testing.T) { f, err := Parse("in", []byte(tc.in)) assert.Nil(t, err) - assert.Equal(t, tc.expected, f.Wip) + assert.Equal(t, tc.expected, f.Draft) }) } } diff --git a/gnovm/pkg/gnomod/read.go b/gnovm/pkg/gnomod/read.go index 25ceb1628b0..206c843f86a 100644 --- a/gnovm/pkg/gnomod/read.go +++ b/gnovm/pkg/gnomod/read.go @@ -834,13 +834,13 @@ func parseDirectiveComment(block *modfile.LineBlock, line *modfile.Line) string return strings.Join(lines, "\n") } -// parseWip returns whether the module is marked as a work in progress. -func parseWip(block *modfile.CommentBlock) bool { +// parseDraft returns whether the module is marked as draft. +func parseDraft(block *modfile.CommentBlock) bool { if len(block.Before) != 1 { return false } comment := block.Before[0] - if strings.TrimSpace(strings.TrimPrefix(comment.Token, "//")) != "WIP" { + if strings.TrimSpace(strings.TrimPrefix(comment.Token, "//")) != "Draft" { return false } return true