Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ To Install Marker CLI quickly, follow the installation instructions.

1. You first need Go installed (version 1.18+ is required), then you can use the below Go command to install Marker CLI.

`$ go get -u github.com/procyon-projects/marker/...`
`$ go get -u github.com/procyon-projects/markers/...`
2. Verify that you've installed Marker CLI by typing the following command.

`$ marker version`
Expand Down
4 changes: 2 additions & 2 deletions argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type Argument struct {
Default any
}

func ExtractArgument(structField reflect.StructField) (Argument, error) {
parameterName := UpperCamelCase(structField.Name)
func extractArgument(structField reflect.StructField) (Argument, error) {
parameterName := upperCamelCase(structField.Name)
parameterTag, parameterTagExists := structField.Tag.Lookup("parameter")

if parameterTagExists && parameterTag != "" {
Expand Down
55 changes: 55 additions & 0 deletions argument_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package markers

import (
"github.com/stretchr/testify/assert"
"reflect"
"testing"
)

func TestExtractArgument(t *testing.T) {
reflMarker := reflect.TypeOf(Marker{})

arg, err := extractArgument(reflMarker.Field(0))
assert.Nil(t, err)
assert.Equal(t, "Value", arg.Name)
assert.Empty(t, arg.Default)
assert.True(t, arg.Required)
assert.False(t, arg.Deprecated)

assert.Equal(t, StringType, arg.TypeInfo.ActualType)
assert.False(t, arg.TypeInfo.IsPointer)
assert.Nil(t, arg.TypeInfo.ItemType)
assert.Empty(t, arg.TypeInfo.Enum)

arg, err = extractArgument(reflMarker.Field(2))
assert.Nil(t, err)
assert.Equal(t, "Repeatable", arg.Name)
assert.Empty(t, arg.Default)
assert.False(t, arg.Required)
assert.False(t, arg.Deprecated)

assert.Equal(t, BoolType, arg.TypeInfo.ActualType)
assert.False(t, arg.TypeInfo.IsPointer)
assert.Nil(t, arg.TypeInfo.ItemType)
assert.Empty(t, arg.TypeInfo.Enum)

arg, err = extractArgument(reflMarker.Field(4))
assert.Nil(t, err)
assert.Equal(t, "Targets", arg.Name)
assert.Empty(t, arg.Default)
assert.True(t, arg.Required)
assert.False(t, arg.Deprecated)

assert.Equal(t, SliceType, arg.TypeInfo.ActualType)
assert.Equal(t, StringType, arg.TypeInfo.ItemType.ActualType)
assert.False(t, arg.TypeInfo.IsPointer)
assert.Equal(t, map[string]interface{}{
"FIELD_LEVEL": "FIELD_LEVEL",
"FUNCTION_LEVEL": "FUNCTION_LEVEL",
"INTERFACE_METHOD_LEVEL": "INTERFACE_METHOD_LEVEL",
"INTERFACE_TYPE_LEVEL": "INTERFACE_TYPE_LEVEL",
"PACKAGE_LEVEL": "PACKAGE_LEVEL",
"STRUCT_METHOD_LEVEL": "STRUCT_METHOD_LEVEL",
"STRUCT_TYPE_LEVEL": "STRUCT_TYPE_LEVEL",
}, arg.TypeInfo.Enum)
}
2 changes: 1 addition & 1 deletion argument_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (typeInfo ArgumentTypeInfo) parseInteger(scanner *Scanner, out reflect.Valu
}

if !scanner.Expect(IntegerValue, "Integer") {
return nil
return fmt.Errorf("expected integer, got %q", scanner.Token())
}

text := scanner.Token()
Expand Down
74 changes: 74 additions & 0 deletions argument_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,33 @@ func TestArgumentTypeInfo_ParseBoolean(t *testing.T) {
assert.False(t, boolValue)
}

func TestArgumentTypeInfo_ParseBooleanShouldReturnErrorIfScannedTokenIsNotBooleanValue(t *testing.T) {
typeInfo, err := ArgumentTypeInfoFromType(reflect.TypeOf(true))
assert.Nil(t, err)
assert.Equal(t, BoolType, typeInfo.ActualType)

boolValue := false

scanner := NewScanner("test")
scanner.Peek()

err = typeInfo.parseBoolean(scanner, reflect.ValueOf(&boolValue))
assert.NotNil(t, err)
assert.Equal(t, "expected true or false, got \"test\"", err.Error())
}

func TestArgumentTypeInfo_ParseBooleanShouldReturnErrorIfScannerIsNil(t *testing.T) {
typeInfo, err := ArgumentTypeInfoFromType(reflect.TypeOf(true))
assert.Nil(t, err)
assert.Equal(t, BoolType, typeInfo.ActualType)

boolValue := false

err = typeInfo.parseBoolean(nil, reflect.ValueOf(&boolValue))
assert.NotNil(t, err)
assert.Equal(t, "scanner cannot be nil", err.Error())
}

func TestArgumentTypeInfo_ParseInteger(t *testing.T) {
typeInfo, err := ArgumentTypeInfoFromType(reflect.TypeOf(0))
assert.Nil(t, err)
Expand Down Expand Up @@ -300,6 +327,33 @@ func TestArgumentTypeInfo_ParseInteger(t *testing.T) {
assert.Equal(t, uint(70519), unsignedIntegerValue)
}

func TestArgumentTypeInfo_parseIntegerShouldReturnErrorIfScannedTokenIsNotIntegerValue(t *testing.T) {
typeInfo, err := ArgumentTypeInfoFromType(reflect.TypeOf(2))
assert.Nil(t, err)
assert.Equal(t, SignedIntegerType, typeInfo.ActualType)

signedIntegerValue := 0

scanner := NewScanner("test")
scanner.Peek()

err = typeInfo.parseInteger(scanner, reflect.ValueOf(&signedIntegerValue))
assert.NotNil(t, err)
assert.Equal(t, "expected integer, got \"test\"", err.Error())
}

func TestArgumentTypeInfo_parseIntegerShouldReturnErrorIfScannerIsNil(t *testing.T) {
typeInfo, err := ArgumentTypeInfoFromType(reflect.TypeOf(5))
assert.Nil(t, err)
assert.Equal(t, SignedIntegerType, typeInfo.ActualType)

signedIntegerValue := 0

err = typeInfo.parseInteger(nil, reflect.ValueOf(&signedIntegerValue))
assert.NotNil(t, err)
assert.Equal(t, "scanner cannot be nil", err.Error())
}

func TestArgumentTypeInfo_ParseMap(t *testing.T) {
m := make(map[string]any)
typeInfo, err := ArgumentTypeInfoFromType(reflect.TypeOf(&m))
Expand Down Expand Up @@ -336,6 +390,16 @@ func TestArgumentTypeInfo_ParseMap(t *testing.T) {
assert.Equal(t, "anyValue2", m["anyKey4"])
}

func TestArgumentTypeInfo_parseMapShouldReturnErrorIfScannerIsNil(t *testing.T) {
typeInfo, err := ArgumentTypeInfoFromType(reflect.TypeOf(map[string]any{}))
assert.Nil(t, err)
assert.Equal(t, MapType, typeInfo.ActualType)

err = typeInfo.parseMap(nil, reflect.ValueOf(""))
assert.NotNil(t, err)
assert.Equal(t, "scanner cannot be nil", err.Error())
}

func TestArgumentTypeInfo_ParseSlice(t *testing.T) {
s := make([]int, 0)
typeInfo, err := ArgumentTypeInfoFromType(reflect.TypeOf(&s))
Expand Down Expand Up @@ -372,6 +436,16 @@ func TestArgumentTypeInfo_ParseSlice(t *testing.T) {
assert.Equal(t, []int{1, 2, 3, 4, 5}, s)
}

func TestArgumentTypeInfo_parseSliceShouldReturnErrorIfScannerIsNil(t *testing.T) {
typeInfo, err := ArgumentTypeInfoFromType(reflect.TypeOf([]string{}))
assert.Nil(t, err)
assert.Equal(t, SliceType, typeInfo.ActualType)

err = typeInfo.parseSlice(nil, reflect.ValueOf(""))
assert.NotNil(t, err)
assert.Equal(t, "scanner cannot be nil", err.Error())
}

func TestArgumentTypeInfo_TypeInference(t *testing.T) {
var value any
typeInfo, err := ArgumentTypeInfoFromType(reflect.TypeOf(&value))
Expand Down
4 changes: 2 additions & 2 deletions cmd/marker/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"errors"
"fmt"
"github.com/procyon-projects/marker/internal/cmd"
"github.com/procyon-projects/marker/packages"
"github.com/procyon-projects/markers/internal/cmd"
"github.com/procyon-projects/markers/packages"
"io"
"os"
"os/exec"
Expand Down
2 changes: 1 addition & 1 deletion cmd/marker/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package main

const (
AppName = "marker"
Package = "github.com/procyon-projects/marker"
Package = "github.com/procyon-projects/markers"
Version = "v0.2.8-dev"
)
4 changes: 2 additions & 2 deletions cmd/marker/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"errors"
"fmt"
"github.com/procyon-projects/marker/packages"
"github.com/procyon-projects/marker/processor"
"github.com/procyon-projects/markers/packages"
"github.com/procyon-projects/markers/processor"
"github.com/spf13/cobra"
"os"
)
Expand Down
16 changes: 12 additions & 4 deletions cmd/marker/generate.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package main

import (
"github.com/procyon-projects/marker/packages"
"github.com/procyon-projects/marker/processor"
"github.com/procyon-projects/marker/visitor"
"github.com/procyon-projects/markers/packages"
"github.com/procyon-projects/markers/processor"
"github.com/procyon-projects/markers/visitor"
"os"
"os/exec"
)

func Generate(ctx *processor.Context) {
pkg, _ := ctx.LoadResult().Lookup("github.com/procyon-projects/marker/test/package1")
pkg, _ := ctx.LoadResult().Lookup("github.com/procyon-projects/markers/test/package1")
err := visitor.EachFile(ctx.Collector(), []*packages.Package{pkg}, func(file *visitor.File, err error) error {
if file.NumImportMarkers() == 0 {
return nil
}

/*
f := file.Functions().At(0)
markers, ok := f.Markers().FindByName("shelf:entity")

if ok {

}*/

return err
})

Expand Down
2 changes: 1 addition & 1 deletion cmd/marker/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"errors"
"github.com/procyon-projects/marker/processor"
"github.com/procyon-projects/markers/processor"
"github.com/spf13/cobra"
"log"
"os"
Expand Down
4 changes: 2 additions & 2 deletions cmd/marker/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"encoding/json"
"errors"
"github.com/procyon-projects/marker/packages"
"github.com/procyon-projects/marker/processor"
"github.com/procyon-projects/markers/packages"
"github.com/procyon-projects/markers/processor"
"github.com/spf13/cobra"
"log"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/marker/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/procyon-projects/marker/processor"
"github.com/procyon-projects/markers/processor"
"log"
)

Expand Down
17 changes: 7 additions & 10 deletions cmd/marker/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package main

import (
"errors"
"github.com/procyon-projects/marker"
"github.com/procyon-projects/marker/packages"
"github.com/procyon-projects/marker/processor"
"github.com/procyon-projects/markers/packages"
"github.com/procyon-projects/markers/processor"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
"log"
Expand All @@ -27,8 +26,8 @@ var mainFileContent = `// Code generated by marker; DO NOT EDIT.
package main

import (
"github.com/procyon-projects/marker/cmd"
"github.com/procyon-projects/marker/processor"
"github.com/procyon-projects/markers/cmd"
"github.com/procyon-projects/markers/processor"
"log"
)

Expand All @@ -47,7 +46,7 @@ func main() {
var generateFileContent = `package main

import (
"github.com/procyon-projects/marker/processor"
"github.com/procyon-projects/markers/processor"
)

func Generate(ctx *processor.Context) {
Expand All @@ -58,7 +57,7 @@ func Generate(ctx *processor.Context) {
var validateFileContent = `package main

import (
"github.com/procyon-projects/marker/processor"
"github.com/procyon-projects/markers/processor"
)

func Validate(ctx *processor.Context) {
Expand Down Expand Up @@ -183,9 +182,7 @@ func addProcessorCommand(processorName string) error {
return err
}

if !markers.IsLower(processorName) {
return errors.New("processor name must only contain lower case letters")
}
processorName = strings.ToLower(processorName)

yamlPath := filepath.FromSlash(path.Join(wd, "marker.processors.yaml"))
_, err = os.Stat(yamlPath)
Expand Down
2 changes: 1 addition & 1 deletion cmd/marker/validate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/procyon-projects/marker/processor"
"github.com/procyon-projects/markers/processor"
"os"
"os/exec"
)
Expand Down
Loading