github.com/codingeasygo/util@v0.0.0-20231206062002-1ce2f004b7d9/xmap/replace_test.go (about)

     1  package xmap
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestReplace(t *testing.T) {
     8  	vals := Wrap(map[string]interface{}{
     9  		"int":    1,
    10  		"float":  1.0,
    11  		"string": "abc",
    12  	})
    13  	if vals.ReplaceAll(`${int}`, true, true) != "1" {
    14  		t.Error("error")
    15  		return
    16  	}
    17  	if vals.ReplaceAll(`${float}`, true, true) != "1" {
    18  		t.Error("error")
    19  		return
    20  	}
    21  	if vals.ReplaceAll(`${string}`, true, true) != "abc" {
    22  		t.Error("error")
    23  		return
    24  	}
    25  	if vals.ReplaceAll(`${string}-${int}`, true, true) != "abc-1" {
    26  		t.Error("error")
    27  		return
    28  	}
    29  	if vals.ReplaceAll(`${PWD}`, true, true) == "" {
    30  		t.Error("error")
    31  		return
    32  	}
    33  	if vals.ReplaceAll(`${abc}`, true, true) != "" {
    34  		t.Error("error")
    35  		return
    36  	}
    37  	if vals.ReplaceAll(`${abc}`, true, false) != "${abc}" {
    38  		t.Error("error")
    39  		return
    40  	}
    41  }