本文整理汇总了Golang中bytes.NewBufferString函数的典型用法代码### 示例。如果您正苦于以下问题:Golang NewBufferString函数的具体用法?Golang NewBufferString怎么用?Golang NewBufferString使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。

在下文中一共展示了NewBufferString函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。

示例1: deprecated_init

// this init function is deprecated, but I'm keeping it
// around just in case it proves useful in the future.
func deprecated_init() {
    // if piping from stdin we can just exit
    // and use the default Stdin value
    stat, _ := os.Stdin.Stat()
    if (stat.Mode() & os.ModeCharDevice) == 0 {
        return
    }

    // check for params after the double dash
    // in the command string
    for i, argv := range os.Args {
        if argv == "--" {
            arg := os.Args[i+1]
            buf := bytes.NewBufferString(arg)
            Stdin = NewParamSet(buf)
            return
        }
    }

    // else use the first variable in the list
    if len(os.Args) > 1 {
        buf := bytes.NewBufferString(os.Args[1])
        Stdin = NewParamSet(buf)
    }
}

开发者ID:curx,项目名称:drone-go,代码行数:27,代码来源:plugin.go

示例2: TestDifferentStrings

func TestDifferentStrings(t *testing.T) {
    s1 := "one\ntwo\nthree\nfour\n"
    s2 := "one\nTwo\nthree\nfore\n"
    a, b := bytes.NewBufferString(s1), bytes.NewBufferString(s2)

    diffs, err := text.Compare(a, b)

    if err != nil {
        t.Error(err)
    }
    if len(diffs) != 2 {
        t.Errorf("Expected 2 diffs, got %d", len(diffs))
    }

    if len(diffs) > 0 {
        ed := core.Diff{Expected: "two", Actual: "Two", Pos: []string{"2"}}
        ad := diffs[0]

        if !ad.Equals(ed) {
            t.Errorf("Expected %s but got %s", ed, ad)
        }
    }

    if len(diffs) > 1 {
        ed := core.Diff{Expected: "four", Actual: "fore", Pos: []string{"4"}}
        ad := diffs[1]

        if !ad.Equals(ed) {
            t.Errorf("Expected %s but got %s", ed, ad)
        }
    }
}

开发者ID:toshaf,项目名称:exhibit,代码行数:32,代码来源:text_test.go

示例3: TestDelete

func TestDelete(t *testing.T) {
    buf := bytes.NewBufferString("[general]\nfoo=bar\nfoo2=bar2\nfoo3=baz\n")
    cfg := ini.Parse(buf)
    cfg.Delete("general", "foo")
    out := new(bytes.Buffer)
    cfg.Write(out)
    correct := "[general]\nfoo2=bar2\nfoo3=baz\n\n"

    if s := out.String(); s != correct {
        t.Errorf("Incorrect INI after delete:\n%s", s)
    }

    buf = bytes.NewBufferString("[general]\nfoo=bar\nfoo2=bar2\nfoo3=baz\n")
    cfg = ini.Parse(buf)
    cfg.Delete("general", "foo2")
    out = new(bytes.Buffer)
    cfg.Write(out)
    correct = "[general]\nfoo=bar\nfoo3=baz\n\n"

    if s := out.String(); s != correct {
        t.Errorf("Incorrect INI after delete:\n%s", s)
    }

    buf = bytes.NewBufferString("[general]\nfoo=bar\nfoo2=bar2\nfoo3=baz\n")
    cfg = ini.Parse(buf)
    cfg.Delete("general", "foo3")
    out = new(bytes.Buffer)
    cfg.Write(out)
    correct = "[general]\nfoo=bar\nfoo2=bar2\n\n"

    if s := out.String(); s != correct {
        t.Errorf("Incorrect INI after delete:\n%s", s)
    }
}

开发者ID:calmh,项目名称:mole,代码行数:34,代码来源:ini_test.go

示例4: TestAddPool

func (s *S) TestAddPool(c *check.C) {
    b := bytes.NewBufferString("name=pool1")
    req, err := http.NewRequest("POST", "/pools", b)
    c.Assert(err, check.IsNil)
    req.Header.Set("Authorization", "bearer "+s.token.GetValue())
    req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
    rec := httptest.NewRecorder()
    defer provision.RemovePool("pool1")
    m := RunServer(true)
    m.ServeHTTP(rec, req)
    c.Assert(rec.Code, check.Equals, http.StatusCreated)
    c.Assert(err, check.IsNil)
    pools, err := provision.ListPools(bson.M{"_id": "pool1"})
    c.Assert(err, check.IsNil)
    c.Assert(pools, check.HasLen, 1)
    b = bytes.NewBufferString("name=pool2&public=true")
    req, err = http.NewRequest("POST", "/pools", b)
    c.Assert(err, check.IsNil)
    req.Header.Set("Authorization", "bearer "+s.token.GetValue())
    req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
    rec = httptest.NewRecorder()
    defer provision.RemovePool("pool2")
    m.ServeHTTP(rec, req)
    c.Assert(rec.Code, check.Equals, http.StatusCreated)
    pools, err = provision.ListPools(bson.M{"_id": "pool2"})
    c.Assert(err, check.IsNil)
    c.Assert(pools[0].Public, check.Equals, true)
}

开发者ID:pedrosnk,项目名称:tsuru,代码行数:28,代码来源:pool_test.go

示例5: TestSimpleString

func TestSimpleString(t *testing.T) {
    var data string
    msg := bytes.NewBufferString("+This is a simple string\r\n+This simple string\rfails\r\n")
    err := Scan(msg, &data)
    if err != nil {
        t.Fatal(err)
    }
    t.Logf("%q", data)

    err = Scan(msg, &data)
    if err != ErrMalformedSimpleString {
        t.Fatal("simple string containing \\r did not fail")
    } else {
        t.Logf("err=%v", err)
    }
    t.Logf("%q", data)

    msg = bytes.NewBufferString("+This simple string fails because of a \n\r\n")
    err = Scan(msg, &data)
    if err != ErrMalformedSimpleString {
        t.Fatal("simple string containing \\n did not fail")
    } else {
        t.Logf("err=%v", err)
    }
    t.Logf("%q", data)
}

开发者ID:nilium,项目名称:fred,代码行数:26,代码来源:scan_test.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng