github.com/lhzd863/cherry@v0.0.0-20200403104631-8e2d1d8f2d8a/src/pkg/tests/html_test.go (about)

     1  /*
     2   *                                Copyright (C) 2016 by Rafael Santiago
     3   *
     4   * This is a free software. You can redistribute it and/or modify under
     5   * the terms of the GNU General Public License version 2.
     6   *
     7   */
     8  package cherry_test
     9  
    10  import (
    11  	"os"
    12  	"pkg/config"
    13  	"pkg/config/parser"
    14  	"pkg/html"
    15  	"testing"
    16  )
    17  
    18  func PreprocessorBasicTest(t *testing.T) {
    19  	preprocessor := html.NewHTMLPreprocessor(nil)
    20  	if preprocessor.ExpandData("land-of-competition", "{{.FoD}} Zzz...") != "{{.FoD}} Zzz..." {
    21  		t.Fail()
    22  	}
    23  	var cherry_rooms *config.CherryRooms
    24  	cwd, _ := os.Getwd()
    25  	os.Chdir("../../sample")
    26  	var error *parser.CherryFileError
    27  	cherry_rooms, error = parser.ParseCherryFile("conf/sample.cherry")
    28  	os.Chdir(cwd)
    29  	if error != nil {
    30  		t.Fail()
    31  	}
    32  	preprocessor.Init(cherry_rooms)
    33  	preprocessor.SetDataValue("{{.foo}}", "bar")
    34  	preprocessor.SetDataValue("{{.bar}}", "foo")
    35  	if preprocessor.ExpandData("aliens-on-earth", "{{.foo}}{{.bar}}") != "barfoo" {
    36  		t.Fail()
    37  	}
    38  	if preprocessor.ExpandData("aliens-on-earth", "{{.greeting-message}}") != "Take meeeeee to your leader!!!" {
    39  		t.Fail()
    40  	}
    41  }