Skip to content

Commit

Permalink
technical debt
Browse files Browse the repository at this point in the history
  • Loading branch information
e154 committed Jan 21, 2024
1 parent 51f66ea commit 5be3477
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/scripts/test16_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

func Test16(t *testing.T) {

Convey("scripts run syn command", t, func(ctx C) {
Convey("merge scripts", t, func(ctx C) {
err := container.Invoke(func(adaptors *adaptors.Adaptors,
migrations *migrations.Migrations,
scriptService scripts.ScriptService) {
Expand Down
68 changes: 68 additions & 0 deletions tests/scripts/test17_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// This file is part of the Smart Home
// Program complex distribution https://github.com/e154/smart-home
// Copyright (C) 2016-2023, Filippov Alex
//
// This library is free software: you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library. If not, see
// <https://www.gnu.org/licenses/>.

package scripts

import (
"fmt"
"github.com/e154/smart-home/adaptors"
m "github.com/e154/smart-home/models"
"github.com/e154/smart-home/system/migrations"
"github.com/e154/smart-home/system/scripts"
. "github.com/smartystreets/goconvey/convey"
"testing"
)

func Test17(t *testing.T) {

Convey("concat scripts", t, func(ctx C) {
err := container.Invoke(func(adaptors *adaptors.Adaptors,
migrations *migrations.Migrations,
scriptService scripts.ScriptService) {

// clear database
// ------------------------------------------------
_ = migrations.Purge()

scripts := GetScripts(ctx, scriptService, adaptors, []int{29, 30, 31}...)

engine, err := scriptService.NewEngine(&m.Script{
Lang: "javascript",
})
So(err, ShouldBeNil)

result, err := engine.EvalString(scripts["script29"].Compiled + scripts["script30"].Compiled + scripts["script31"].Compiled)
So(err, ShouldBeNil)
fmt.Println(result)
//So(result, ShouldEqual, "1")

// a + b
result, err = engine.AssertFunction("plus")
So(err, ShouldBeNil)
So(result, ShouldEqual, "3")

// 3 + a
result, err = engine.EvalString("m")
So(err, ShouldBeNil)
So(result, ShouldEqual, "4")
})
if err != nil {
fmt.Println(err.Error())
}
})
}

0 comments on commit 5be3477

Please sign in to comment.