mirror of
https://github.com/MontFerret/ferret.git
synced 2025-02-15 14:03:04 +02:00
Missed updating a bunch of identifiers
This commit is contained in:
parent
a7ecc90973
commit
8942a5e584
@ -55,15 +55,15 @@ func ToIterator(value core.Value) (Iterator, error) {
|
||||
return NewArrayIterator(value.(*values.Array)), nil
|
||||
case core.ObjectType:
|
||||
return NewObjectIterator(value.(*values.Object)), nil
|
||||
case core.HtmlElementType, core.HtmlDocumentType:
|
||||
case core.HTMLElementType, core.HTMLDocumentType:
|
||||
return NewHTMLNodeIterator(value.(values.HTMLNode)), nil
|
||||
default:
|
||||
return nil, core.TypeError(
|
||||
value.Type(),
|
||||
core.ArrayType,
|
||||
core.ObjectType,
|
||||
core.HtmlDocumentType,
|
||||
core.HtmlElementType,
|
||||
core.HTMLDocumentType,
|
||||
core.HTMLElementType,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func GetIn(from core.Value, byPath []core.Value) (core.Value, error) {
|
||||
case "innerText":
|
||||
result = el.InnerText()
|
||||
case "innerHtml":
|
||||
result = el.InnerHtml()
|
||||
result = el.InnerHTML()
|
||||
case "value":
|
||||
result = el.Value()
|
||||
case "attributes":
|
||||
@ -73,7 +73,7 @@ func GetIn(from core.Value, byPath []core.Value) (core.Value, error) {
|
||||
doc, ok := result.(HTMLDocument)
|
||||
|
||||
if ok {
|
||||
result = doc.Url()
|
||||
result = doc.URL()
|
||||
}
|
||||
}
|
||||
default:
|
||||
|
@ -20,8 +20,8 @@ func Length(_ context.Context, inputs ...core.Value) (core.Value, error) {
|
||||
core.StringType,
|
||||
core.ArrayType,
|
||||
core.ObjectType,
|
||||
core.HtmlElementType,
|
||||
core.HtmlDocumentType,
|
||||
core.HTMLElementType,
|
||||
core.HTMLDocumentType,
|
||||
core.BinaryType,
|
||||
)
|
||||
|
||||
|
@ -23,13 +23,13 @@ func Click(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
if len(args) == 1 {
|
||||
arg1 := args[0]
|
||||
|
||||
err := core.ValidateType(arg1, core.HtmlElementType)
|
||||
err := core.ValidateType(arg1, core.HTMLElementType)
|
||||
|
||||
if err != nil {
|
||||
return values.False, err
|
||||
}
|
||||
|
||||
el, ok := arg1.(*dynamic.HtmlElement)
|
||||
el, ok := arg1.(*dynamic.HTMLElement)
|
||||
|
||||
if !ok {
|
||||
return values.False, core.Error(core.ErrInvalidType, "expected dynamic element")
|
||||
@ -42,13 +42,13 @@ func Click(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
arg1 := args[0]
|
||||
selector := args[1].String()
|
||||
|
||||
err = core.ValidateType(arg1, core.HtmlDocumentType)
|
||||
err = core.ValidateType(arg1, core.HTMLDocumentType)
|
||||
|
||||
if err != nil {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
doc, ok := arg1.(*dynamic.HtmlDocument)
|
||||
doc, ok := arg1.(*dynamic.HTMLDocument)
|
||||
|
||||
if !ok {
|
||||
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||
@ -73,13 +73,13 @@ func ClickAll(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
arg1 := args[0]
|
||||
selector := args[1].String()
|
||||
|
||||
err = core.ValidateType(arg1, core.HtmlDocumentType)
|
||||
err = core.ValidateType(arg1, core.HTMLDocumentType)
|
||||
|
||||
if err != nil {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
doc, ok := arg1.(*dynamic.HtmlDocument)
|
||||
doc, ok := arg1.(*dynamic.HTMLDocument)
|
||||
|
||||
if !ok {
|
||||
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||
@ -102,7 +102,7 @@ func Navigate(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
err = core.ValidateType(args[0], core.HtmlDocumentType)
|
||||
err = core.ValidateType(args[0], core.HTMLDocumentType)
|
||||
|
||||
if err != nil {
|
||||
return values.None, err
|
||||
@ -114,7 +114,7 @@ func Navigate(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
doc, ok := args[0].(*dynamic.HtmlDocument)
|
||||
doc, ok := args[0].(*dynamic.HTMLDocument)
|
||||
|
||||
if !ok {
|
||||
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||
@ -141,13 +141,13 @@ func Input(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
if len(args) == 2 {
|
||||
arg1 := args[0]
|
||||
|
||||
err := core.ValidateType(arg1, core.HtmlElementType)
|
||||
err := core.ValidateType(arg1, core.HTMLElementType)
|
||||
|
||||
if err != nil {
|
||||
return values.False, err
|
||||
}
|
||||
|
||||
el, ok := arg1.(*dynamic.HtmlElement)
|
||||
el, ok := arg1.(*dynamic.HTMLElement)
|
||||
|
||||
if !ok {
|
||||
return values.False, core.Error(core.ErrInvalidType, "expected dynamic element")
|
||||
@ -164,7 +164,7 @@ func Input(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
|
||||
arg1 := args[0]
|
||||
|
||||
err = core.ValidateType(arg1, core.HtmlDocumentType)
|
||||
err = core.ValidateType(arg1, core.HTMLDocumentType)
|
||||
|
||||
if err != nil {
|
||||
return values.False, err
|
||||
@ -178,7 +178,7 @@ func Input(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
return values.False, err
|
||||
}
|
||||
|
||||
doc, ok := arg1.(*dynamic.HtmlDocument)
|
||||
doc, ok := arg1.(*dynamic.HTMLDocument)
|
||||
|
||||
if !ok {
|
||||
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||
|
@ -23,13 +23,13 @@ func InnerHTML(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
arg1 := args[0]
|
||||
selector := args[1].String()
|
||||
|
||||
err = core.ValidateType(arg1, core.HtmlDocumentType)
|
||||
err = core.ValidateType(arg1, core.HTMLDocumentType)
|
||||
|
||||
if err != nil {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
doc, ok := arg1.(*dynamic.HtmlDocument)
|
||||
doc, ok := arg1.(*dynamic.HTMLDocument)
|
||||
|
||||
if !ok {
|
||||
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||
@ -54,13 +54,13 @@ func InnerHTMLAll(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
arg1 := args[0]
|
||||
selector := args[1].String()
|
||||
|
||||
err = core.ValidateType(arg1, core.HtmlDocumentType)
|
||||
err = core.ValidateType(arg1, core.HTMLDocumentType)
|
||||
|
||||
if err != nil {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
doc, ok := arg1.(*dynamic.HtmlDocument)
|
||||
doc, ok := arg1.(*dynamic.HTMLDocument)
|
||||
|
||||
if !ok {
|
||||
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||
@ -85,13 +85,13 @@ func InnerText(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
arg1 := args[0]
|
||||
selector := args[1].String()
|
||||
|
||||
err = core.ValidateType(arg1, core.HtmlDocumentType)
|
||||
err = core.ValidateType(arg1, core.HTMLDocumentType)
|
||||
|
||||
if err != nil {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
doc, ok := arg1.(*dynamic.HtmlDocument)
|
||||
doc, ok := arg1.(*dynamic.HTMLDocument)
|
||||
|
||||
if !ok {
|
||||
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||
@ -116,13 +116,13 @@ func InnerTextAll(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
arg1 := args[0]
|
||||
selector := args[1].String()
|
||||
|
||||
err = core.ValidateType(arg1, core.HtmlDocumentType)
|
||||
err = core.ValidateType(arg1, core.HTMLDocumentType)
|
||||
|
||||
if err != nil {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
doc, ok := arg1.(*dynamic.HtmlDocument)
|
||||
doc, ok := arg1.(*dynamic.HTMLDocument)
|
||||
|
||||
if !ok {
|
||||
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||
|
@ -17,7 +17,7 @@ const (
|
||||
)
|
||||
|
||||
type Driver interface {
|
||||
GetDocument(ctx context.Context, url string) (values.HtmlNode, error)
|
||||
GetDocument(ctx context.Context, url string) (values.HTMLNode, error)
|
||||
Close() error
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ type HTMLDocument struct {
|
||||
client *cdp.Client
|
||||
events *events.EventBroker
|
||||
url values.String
|
||||
element *HtmlElement
|
||||
element *HTMLElement
|
||||
}
|
||||
|
||||
func LoadHTMLDocument(
|
||||
@ -144,7 +144,7 @@ func NewHTMLDocument(
|
||||
doc.conn = conn
|
||||
doc.client = client
|
||||
doc.events = broker
|
||||
doc.element = NewHtmlElement(doc.logger, client, broker, root.NodeID, root, innerHTML)
|
||||
doc.element = NewHTMLElement(doc.logger, client, broker, root.NodeID, root, innerHTML)
|
||||
doc.url = ""
|
||||
|
||||
if root.BaseURL != nil {
|
||||
@ -170,7 +170,7 @@ func NewHTMLDocument(
|
||||
doc.element.Close()
|
||||
|
||||
// create a new root element wrapper
|
||||
doc.element = NewHtmlElement(doc.logger, client, broker, updated.NodeID, updated, innerHTML)
|
||||
doc.element = NewHTMLElement(doc.logger, client, broker, updated.NodeID, updated, innerHTML)
|
||||
doc.url = ""
|
||||
|
||||
if updated.BaseURL != nil {
|
||||
|
@ -28,7 +28,7 @@ func NewDriver(address string) *Driver {
|
||||
return drv
|
||||
}
|
||||
|
||||
func (drv *Driver) GetDocument(ctx context.Context, url string) (values.HtmlNode, error) {
|
||||
func (drv *Driver) GetDocument(ctx context.Context, url string) (values.HTMLNode, error) {
|
||||
err := drv.init(ctx)
|
||||
|
||||
if err != nil {
|
||||
@ -58,7 +58,7 @@ func (drv *Driver) GetDocument(ctx context.Context, url string) (values.HtmlNode
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return LoadHtmlDocument(ctx, conn, url)
|
||||
return LoadHTMLDocument(ctx, conn, url)
|
||||
}
|
||||
|
||||
func (drv *Driver) Close() error {
|
||||
|
@ -160,7 +160,7 @@ func (el *HTMLElement) String() string {
|
||||
|
||||
func (el *HTMLElement) Compare(other core.Value) int {
|
||||
switch other.Type() {
|
||||
case core.HtmlDocumentType:
|
||||
case core.HTMLDocumentType:
|
||||
other := other.(*HTMLElement)
|
||||
|
||||
id := int(el.id)
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
type HTMLDocument struct {
|
||||
*HtmlElement
|
||||
*HTMLElement
|
||||
url values.String
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ func NewHTMLDocument(
|
||||
return nil, core.Error(core.ErrMissedArgument, "document root selection")
|
||||
}
|
||||
|
||||
el, err := NewHtmlElement(node.Selection)
|
||||
el, err := NewHTMLElement(node.Selection)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -228,7 +228,7 @@ func TestDocument(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
el, err := static.NewHtmlElement(doc.Selection)
|
||||
el, err := static.NewHTMLElement(doc.Selection)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
|
@ -83,7 +83,7 @@ func (el *HTMLElement) NodeType() values.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
return values.NewInt(common.ToHtmlType(nodes[0].Type))
|
||||
return values.NewInt(common.ToHTMLType(nodes[0].Type))
|
||||
}
|
||||
|
||||
func (el *HTMLElement) NodeName() values.String {
|
||||
|
@ -250,7 +250,7 @@ func TestElement(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
el, err := static.NewHtmlElement(doc.Find("body"))
|
||||
el, err := static.NewHTMLElement(doc.Find("body"))
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
@ -266,7 +266,7 @@ func TestElement(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
el, err := static.NewHtmlElement(doc.Find("body"))
|
||||
el, err := static.NewHTMLElement(doc.Find("body"))
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
@ -290,7 +290,7 @@ func TestElement(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
el, err := static.NewHtmlElement(doc.Find("body"))
|
||||
el, err := static.NewHTMLElement(doc.Find("body"))
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
@ -315,7 +315,7 @@ func TestElement(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
el, err := static.NewHtmlElement(doc.Find("#q"))
|
||||
el, err := static.NewHTMLElement(doc.Find("#q"))
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
@ -342,7 +342,7 @@ func TestElement(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
el, err := static.NewHtmlElement(doc.Find("h2"))
|
||||
el, err := static.NewHTMLElement(doc.Find("h2"))
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
@ -369,11 +369,11 @@ func TestElement(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
el, err := static.NewHtmlElement(doc.Find("#content"))
|
||||
el, err := static.NewHTMLElement(doc.Find("#content"))
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
v := el.InnerHtml()
|
||||
v := el.InnerHTML()
|
||||
|
||||
So(v, ShouldEqual, "<h2>Ferret</h2>")
|
||||
})
|
||||
@ -385,7 +385,7 @@ func TestElement(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
el, err := static.NewHtmlElement(doc.Find("body .card-img-top:nth-child(1)"))
|
||||
el, err := static.NewHTMLElement(doc.Find("body .card-img-top:nth-child(1)"))
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
|
@ -28,7 +28,7 @@ func NewDriver(setters ...Option) *Driver {
|
||||
return &Driver{client}
|
||||
}
|
||||
|
||||
func (d *Driver) GetDocument(_ context.Context, url string) (values.HtmlNode, error) {
|
||||
func (d *Driver) GetDocument(_ context.Context, url string) (values.HTMLNode, error) {
|
||||
req, err := httpx.NewRequest(httpx.MethodGet, url, nil)
|
||||
|
||||
if err != nil {
|
||||
@ -55,10 +55,10 @@ func (d *Driver) GetDocument(_ context.Context, url string) (values.HtmlNode, er
|
||||
return nil, errors.Wrapf(err, "failed to parse a document %s", url)
|
||||
}
|
||||
|
||||
return NewHtmlDocument(url, doc)
|
||||
return NewHTMLDocument(url, doc)
|
||||
}
|
||||
|
||||
func (d *Driver) ParseDocument(_ context.Context, str string) (values.HtmlNode, error) {
|
||||
func (d *Driver) ParseDocument(_ context.Context, str string) (values.HTMLNode, error) {
|
||||
buf := bytes.NewBuffer([]byte(str))
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(buf)
|
||||
@ -67,7 +67,7 @@ func (d *Driver) ParseDocument(_ context.Context, str string) (values.HtmlNode,
|
||||
return nil, errors.Wrap(err, "failed to parse a document")
|
||||
}
|
||||
|
||||
return NewHtmlDocument("#string", doc)
|
||||
return NewHTMLDocument("#string", doc)
|
||||
}
|
||||
|
||||
func (d *Driver) Close() error {
|
||||
|
@ -26,7 +26,7 @@ func Elements(_ context.Context, inputs ...core.Value) (core.Value, error) {
|
||||
return el.QuerySelectorAll(selector), nil
|
||||
}
|
||||
|
||||
func elementArgs(inputs []core.Value) (values.HtmlNode, values.String, error) {
|
||||
func elementArgs(inputs []core.Value) (values.HTMLNode, values.String, error) {
|
||||
if len(inputs) == 0 {
|
||||
return nil, values.EmptyString, core.Error(core.ErrMissedArgument, "element and arg2")
|
||||
}
|
||||
@ -38,14 +38,14 @@ func elementArgs(inputs []core.Value) (values.HtmlNode, values.String, error) {
|
||||
arg1 := inputs[0]
|
||||
arg2 := inputs[1]
|
||||
|
||||
if arg1.Type() != core.HtmlDocumentType &&
|
||||
arg1.Type() != core.HtmlElementType {
|
||||
return nil, values.EmptyString, core.TypeError(arg1.Type(), core.HtmlDocumentType, core.HtmlElementType)
|
||||
if arg1.Type() != core.HTMLDocumentType &&
|
||||
arg1.Type() != core.HTMLElementType {
|
||||
return nil, values.EmptyString, core.TypeError(arg1.Type(), core.HTMLDocumentType, core.HTMLElementType)
|
||||
}
|
||||
|
||||
if arg2.Type() != core.StringType {
|
||||
return nil, values.EmptyString, core.TypeError(arg2.Type(), core.StringType)
|
||||
}
|
||||
|
||||
return arg1.(values.HtmlNode), arg2.(values.String), nil
|
||||
return arg1.(values.HTMLNode), arg2.(values.String), nil
|
||||
}
|
||||
|
@ -24,13 +24,13 @@ func WaitElement(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
}
|
||||
}
|
||||
|
||||
err = core.ValidateType(arg, core.HtmlDocumentType)
|
||||
err = core.ValidateType(arg, core.HTMLDocumentType)
|
||||
|
||||
if err != nil {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
doc, ok := arg.(*dynamic.HtmlDocument)
|
||||
doc, ok := arg.(*dynamic.HTMLDocument)
|
||||
|
||||
if !ok {
|
||||
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||
@ -46,13 +46,13 @@ func WaitNavigation(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
err = core.ValidateType(args[0], core.HtmlDocumentType)
|
||||
err = core.ValidateType(args[0], core.HTMLDocumentType)
|
||||
|
||||
if err != nil {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
doc, ok := args[0].(*dynamic.HtmlDocument)
|
||||
doc, ok := args[0].(*dynamic.HTMLDocument)
|
||||
|
||||
if !ok {
|
||||
return values.None, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||
|
@ -14,8 +14,8 @@ func NewLib() map[string]core.Function {
|
||||
"CLICK_ALL": ClickAll,
|
||||
"NAVIGATE": Navigate,
|
||||
"INPUT": Input,
|
||||
"INNER_HTML": InnerHtml,
|
||||
"INNER_HTML_ALL": InnerHtmlAll,
|
||||
"INNER_HTML": InnerHTML,
|
||||
"INNER_HTML_ALL": InnerHTMLAll,
|
||||
"INNER_TEXT": InnerText,
|
||||
"INNER_TEXT_ALL": InnerTextAll,
|
||||
}
|
||||
|
@ -9,11 +9,11 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestJsonParse(t *testing.T) {
|
||||
func TestJSONParse(t *testing.T) {
|
||||
Convey("When args are not passed", t, func() {
|
||||
Convey("It should return an error", func() {
|
||||
var err error
|
||||
_, err = strings.JsonParse(context.Background())
|
||||
_, err = strings.JSONParse(context.Background())
|
||||
|
||||
So(err, ShouldBeError)
|
||||
})
|
||||
@ -26,7 +26,7 @@ func TestJsonParse(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := strings.JsonParse(
|
||||
out, err := strings.JSONParse(
|
||||
context.Background(),
|
||||
values.NewString(string(b)),
|
||||
)
|
||||
@ -42,7 +42,7 @@ func TestJsonParse(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := strings.JsonParse(
|
||||
out, err := strings.JSONParse(
|
||||
context.Background(),
|
||||
values.NewString(string(b)),
|
||||
)
|
||||
@ -58,7 +58,7 @@ func TestJsonParse(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := strings.JsonParse(
|
||||
out, err := strings.JSONParse(
|
||||
context.Background(),
|
||||
values.NewString(string(b)),
|
||||
)
|
||||
@ -74,7 +74,7 @@ func TestJsonParse(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := strings.JsonParse(
|
||||
out, err := strings.JSONParse(
|
||||
context.Background(),
|
||||
values.NewString(string(b)),
|
||||
)
|
||||
@ -90,7 +90,7 @@ func TestJsonParse(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := strings.JsonParse(
|
||||
out, err := strings.JSONParse(
|
||||
context.Background(),
|
||||
values.NewString(string(b)),
|
||||
)
|
||||
@ -110,7 +110,7 @@ func TestJsonParse(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := strings.JsonParse(
|
||||
out, err := strings.JSONParse(
|
||||
context.Background(),
|
||||
values.NewString(string(b)),
|
||||
)
|
||||
@ -128,7 +128,7 @@ func TestJsonParse(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := strings.JsonParse(
|
||||
out, err := strings.JSONParse(
|
||||
context.Background(),
|
||||
values.NewString(string(b)),
|
||||
)
|
||||
@ -139,18 +139,18 @@ func TestJsonParse(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestJsonStringify(t *testing.T) {
|
||||
func TestJSONStringify(t *testing.T) {
|
||||
Convey("When args are not passed", t, func() {
|
||||
Convey("It should return an error", func() {
|
||||
var err error
|
||||
_, err = strings.JsonStringify(context.Background())
|
||||
_, err = strings.JSONStringify(context.Background())
|
||||
|
||||
So(err, ShouldBeError)
|
||||
})
|
||||
})
|
||||
|
||||
Convey("It should serialize none", t, func() {
|
||||
out, err := strings.JsonStringify(
|
||||
out, err := strings.JSONStringify(
|
||||
context.Background(),
|
||||
values.None,
|
||||
)
|
||||
@ -160,7 +160,7 @@ func TestJsonStringify(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("It should serialize boolean", t, func() {
|
||||
out, err := strings.JsonStringify(
|
||||
out, err := strings.JSONStringify(
|
||||
context.Background(),
|
||||
values.False,
|
||||
)
|
||||
@ -170,7 +170,7 @@ func TestJsonStringify(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("It should serialize string", t, func() {
|
||||
out, err := strings.JsonStringify(
|
||||
out, err := strings.JSONStringify(
|
||||
context.Background(),
|
||||
values.NewString("foobar"),
|
||||
)
|
||||
@ -180,7 +180,7 @@ func TestJsonStringify(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("It should serialize int", t, func() {
|
||||
out, err := strings.JsonStringify(
|
||||
out, err := strings.JSONStringify(
|
||||
context.Background(),
|
||||
values.NewInt(1),
|
||||
)
|
||||
@ -190,7 +190,7 @@ func TestJsonStringify(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("It should serialize float", t, func() {
|
||||
out, err := strings.JsonStringify(
|
||||
out, err := strings.JSONStringify(
|
||||
context.Background(),
|
||||
values.NewFloat(1.1),
|
||||
)
|
||||
@ -200,7 +200,7 @@ func TestJsonStringify(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("It should serialize array", t, func() {
|
||||
out, err := strings.JsonStringify(
|
||||
out, err := strings.JSONStringify(
|
||||
context.Background(),
|
||||
values.NewArrayWith(
|
||||
values.NewString("foo"),
|
||||
@ -216,7 +216,7 @@ func TestJsonStringify(t *testing.T) {
|
||||
obj := values.NewObject()
|
||||
obj.Set(values.NewString("foo"), values.NewString("bar"))
|
||||
|
||||
out, err := strings.JsonStringify(
|
||||
out, err := strings.JSONStringify(
|
||||
context.Background(),
|
||||
obj,
|
||||
)
|
||||
@ -230,7 +230,7 @@ func TestJsonStringify(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
out, err := strings.JsonStringify(
|
||||
out, err := strings.JSONStringify(
|
||||
context.Background(),
|
||||
obj,
|
||||
)
|
||||
|
@ -10,8 +10,8 @@ func NewLib() map[string]core.Function {
|
||||
"ENCODE_URI_COMPONENT": EncodeURIComponent,
|
||||
"FIND_FIRST": FindFirst,
|
||||
"FIND_LAST": FindLast,
|
||||
"JSON_PARSE": JsonParse,
|
||||
"JSON_STRINGIFY": JsonStringify,
|
||||
"JSON_PARSE": JSONParse,
|
||||
"JSON_STRINGIFY": JSONStringify,
|
||||
"LEFT": Left,
|
||||
"LIKE": Like,
|
||||
"LOWER": Lower,
|
||||
|
@ -60,8 +60,8 @@ func ToArray(_ context.Context, inputs ...core.Value) (core.Value, error) {
|
||||
core.FloatType,
|
||||
core.StringType,
|
||||
core.DateTimeType,
|
||||
core.HtmlElementType,
|
||||
core.HtmlDocumentType:
|
||||
core.HTMLElementType,
|
||||
core.HTMLDocumentType:
|
||||
return values.NewArrayWith(value), nil
|
||||
case core.ArrayType:
|
||||
return value, nil
|
||||
|
@ -18,8 +18,8 @@ func NewLib() map[string]core.Function {
|
||||
"IS_DATETIME": IsDateTime,
|
||||
"IS_ARRAY": IsArray,
|
||||
"IS_OBJECT": IsObject,
|
||||
"IS_HTML_ELEMENT": IsHtmlElement,
|
||||
"IS_HTML_DOCUMENT": IsHtmlDocument,
|
||||
"IS_HTML_ELEMENT": IsHTMLElement,
|
||||
"IS_HTML_DOCUMENT": IsHTMLDocument,
|
||||
"IS_BINARY": IsBinary,
|
||||
"TYPENAME": TypeName,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user