示例#1
0
func Test_Dropcrnl(t *testing.T) {
	testhelpers.AssertString(t, "", string(Dropcrnl([]byte(""))))
	testhelpers.AssertString(t, "h", string(Dropcrnl([]byte("h"))))
	testhelpers.AssertString(t, "hello", string(Dropcrnl([]byte("hello"))))
	testhelpers.AssertString(t, "hello\nthere", string(Dropcrnl([]byte("hello\r\nthere"))))
	testhelpers.AssertString(t, "hello\nthere", string(Dropcrnl([]byte("hello\nthere"))))
}
示例#2
0
func Test_Runemodulus(t *testing.T) {

	b, r := Runemodulus([]byte("abcd"))
	testhelpers.AssertString(t, "abcd", string(b))
	testhelpers.AssertInt(t, 0, len(r))

	// 日本語  <- 3 Asian letters.
	s := "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
	sb := []byte(s)

	b, r = Runemodulus(sb)
	testhelpers.AssertString(t, s, string(b))
	testhelpers.AssertInt(t, 0, len(r))

	b, r = Runemodulus(sb[:len(sb)-1])
	testhelpers.AssertString(t, s[0:6], string(b))
	testhelpers.AssertInt(t, 2, len(r))
	testhelpers.AssertInt(t, int(int(r[0])), '\xe8')
	testhelpers.AssertInt(t, int(int(r[1])), '\xaa')

	b, r = Runemodulus(sb[:len(sb)-2])
	testhelpers.AssertInt(t, 1, len(r))
	testhelpers.AssertString(t, s[0:6], string(b))
	testhelpers.AssertInt(t, int(r[0]), '\xe8')

}
示例#3
0
func Test_VerifyRequiredFields_inbook_editor(t *testing.T) {
	err := VerifyRequiredFields("inbook", []string{"bibkey", "author", "title", "chapter", "publisher", "year"})
	if err != nil {
		t.Error("wrongly claim that valid author/chapter inbook keys are invalid: " + err.Error())
	}

	err = VerifyRequiredFields("inbook", []string{"bibkey", "editor", "title", "chapter", "publisher", "year"})
	if err != nil {
		t.Error("wrongly claim that valid editor/chapter inbook keys are invalid: " + err.Error())
	}

	err = VerifyRequiredFields("inbook", []string{"bibkey", "author", "title", "pages", "publisher", "year"})
	if err != nil {
		t.Error("wrongly claim that valid author/pages inbook keys are invalid: " + err.Error())
	}

	err = VerifyRequiredFields("inbook", []string{"bibkey", "editor", "title", "pages", "publisher", "year"})
	if err != nil {
		t.Error("wrongly claim that valid editor/pages inbook keys are invalid: " + err.Error())
	}

	err = VerifyRequiredFields("inbook", []string{"bibkey", "editor", "title", "publisher", "year"})
	if err == nil {
		t.Error("for editor inbook, wrongly claim missing both pages and chapter is correct")
	} else {
		testhelpers.AssertString(t, "Missing required fields: chapter pages for entry type inbook", err.Error())
	}

	err = VerifyRequiredFields("inbook", []string{"bibkey", "author", "title", "publisher", "year"})
	if err == nil {
		t.Error("for author inbook, wrongly claim missing both pages and chapter is correct")
	} else {
		testhelpers.AssertString(t, "Missing required fields: chapter pages for entry type inbook", err.Error())
	}
}
示例#4
0
func Test_UniqueValidName(t *testing.T) {
	realisticdate, _ := article.ParseDateUnix("1999/03/21 17:00:00")

	nd := &MockSystem{false, time.Time{}}
	testhelpers.AssertString(t, "hello/there.md", UniqueValidName("hello/", "there", ".md", nd))

	nd = &MockSystem{true, realisticdate}
	testhelpers.AssertString(t, "hello/there-19990321-170000.md", UniqueValidName("hello/", "there", ".md", nd))
}
示例#5
0
func Test_Delete_spanning_offset(t *testing.T) {
	ws := New()
	ws.Move(2)
	ws.Addtyping([]byte{'a', 'b', 'c'}, 2)
	testhelpers.AssertString(t, "abc", ws.String())

	n := ws.Delete(1, 3)
	testhelpers.AssertString(t, "bc", ws.String())
	testhelpers.AssertInt(t, 1, n)
}
示例#6
0
func Test_ExtraKeysString(t *testing.T) {
	m := MetaData{"", never, never, "", false, []string{}, map[string]string{"a": "b"}}
	testhelpers.AssertString(t, "a:b", m.ExtraKeysString())

	m = MetaData{"", never, never, "", false, []string{}, map[string]string{"a": "b", "c": "d"}}
	testhelpers.AssertString(t, "a:b, c:d", m.ExtraKeysString())

	m = MetaData{"", never, never, "", false, []string{}, map[string]string{"c": "d", "a": "b"}}
	testhelpers.AssertString(t, "a:b, c:d", m.ExtraKeysString())
}
示例#7
0
func Test_PrettyDate(t *testing.T) {
	statdate, _ := ParseDateUnix("1999/03/21 17:00:00")
	tagdate, _ := ParseDateUnix("2012/03/19 06:51:15")

	md := MetaData{"", statdate, never, "What I want 0", false, []string{}, map[string]string{}}
	testhelpers.AssertString(t, "Sunday, Mar 21, 1999", md.PrettyDate())

	md = MetaData{"", statdate, tagdate, "What I want 0", true, []string{}, map[string]string{}}
	testhelpers.AssertString(t, "Monday, Mar 19, 2012", md.PrettyDate())
}
示例#8
0
func Test_Delete_multi(t *testing.T) {
	ws := New()
	ws.Move(2)
	ws.Addtyping([]byte{'a', 'b', 'c'}, 2)
	testhelpers.AssertString(t, "abc", ws.String())

	n := ws.Delete(3, 5)
	testhelpers.AssertString(t, "a", ws.String())
	testhelpers.AssertInt(t, 0, n)
}
示例#9
0
func Test_Sendtype(t *testing.T) {
	mock := &mockttyfd{make([][]byte, 0, 10)}
	tp := New(mock, Makecho())

	tp.addtype([]byte("hello\nbye"), 0, false)
	tp.Sendtype()

	testhelpers.AssertInt(t, 1, len(mock.writes))
	testhelpers.AssertString(t, "hello\n", string(mock.writes[0]))
	testhelpers.AssertString(t, "bye", string(tp.Typing))
}
示例#10
0
func Test_TypeCook(t *testing.T) {
	mock := &mockttyfd{make([][]byte, 0, 10)}
	tp := New(mock, Makecho())

	s := "hello\n"
	e := &acme.Event{Nr: len(s), Text: []byte(s)}
	tp.Type(e)

	testhelpers.AssertInt(t, 1, len(mock.writes))
	testhelpers.AssertString(t, "hello\n", string(mock.writes[0]))
	testhelpers.AssertString(t, "", string(tp.Typing))
	testhelpers.AssertBool(t, true, tp.cook)
}
示例#11
0
func Test_Cancel_Wholeword(t *testing.T) {
	echo := Makecho()
	echo.echoed([]byte("hello"))

	s := []byte("h")
	r := echo.Cancel(s)
	testhelpers.AssertInt(t, 0, len(r))
	testhelpers.AssertString(t, "ello", string(echo.oldest))

	s = []byte("e")
	r = echo.Cancel(s)
	testhelpers.AssertInt(t, 0, len(r))
	testhelpers.AssertString(t, "llo", string(echo.oldest))
}
示例#12
0
func Test_ExploreTemplating(t *testing.T) {
	s, e := CreateBibTexEntry([]string{"@book"}, map[string]string{"bib-bibkey": "jones2013", "bib-editor": "Peyton Jones", "bib-title": "Collected Angst", "bib-publisher": "Penguin", "bib-year": "2013"})
	if e != nil {
		t.Error("CreateBibTexEntry wrongly failed with: " + e.Error())
	}
	testhelpers.AssertString(t, output1, s)

	s, e = CreateBibTexEntry([]string{"@book", "@bibtex-article"}, map[string]string{"bib-bibkey": "jones2013", "bib-editor": "Peyton Jones", "bib-title": "Collected Angst", "bib-publisher": "Penguin", "bib-year": "2013"})
	if e == nil {
		t.Error("CreateBibTexEntry wrongly succeeded")
	} else {
		testhelpers.AssertString(t, "", s)
		testhelpers.AssertString(t, "Missing required fields: author journal for entry type article", e.Error())
	}
}
示例#13
0
func Test_addtype(t *testing.T) {
	tp := New(new(mockttyfd), Makecho())

	tp.addtype([]byte("hello"), 0, false)
	testhelpers.AssertString(t, "hello", tp.String())

	// addtype is doing the wrong thing...
	tp.addtype([]byte{3}, len("hello"), false)
	testhelpers.AssertString(t, "hello", tp.String())

	// addtype is doing the wrong thing...
	tp.addtype([]byte{3}, len("hello_"), true)
	testhelpers.AssertString(t, "", tp.String())

}
示例#14
0
func Test_Labelcommand_hasend_with_space(t *testing.T) {
	b, r := Labelcommand([]byte("hel\007lo"))
	if r != nil {
		t.Error("incomplete command should have no label")
	}
	testhelpers.AssertString(t, "hel\007lo", string(b))
}
示例#15
0
func Test_Delete_before_offset(t *testing.T) {
	ws := New()
	ws.Move(2)

	n := ws.Delete(1, 2)
	testhelpers.AssertString(t, "", ws.String())
	testhelpers.AssertInt(t, 1, n)
}
示例#16
0
func Test_Reset(t *testing.T) {
	ws := New()
	ws.Move(2)
	ws.Addtyping([]byte{'b'}, 2)

	ws.Reset()
	testhelpers.AssertString(t, "", ws.String())
}
示例#17
0
func Test_Delete_panic(t *testing.T) {
	ws := New()
	ws.Move(2)
	ws.Addtyping([]byte{'a', 'b', 'c'}, 2)
	testhelpers.AssertString(t, "abc", ws.String())

	defer func() {
		if e := recover(); e != nil {
			s := e.(string)
			testhelpers.AssertString(t, "Delete went wrong", s)
		} else {
			t.Fail()
		}
	}()

	ws.Delete(5, 6)
}
示例#18
0
func Test_Cancel_Terminating_NL_Not_Cancelled(t *testing.T) {
	echo := Makecho()
	echo.echoed([]byte("ls\n"))

	s := []byte("ls\r\n")
	r := echo.Cancel(s)
	testhelpers.AssertString(t, "", string(r))
}
示例#19
0
func Test_Delete_to_empty(t *testing.T) {
	ws := New()
	ws.Move(2)
	ws.Addtyping([]byte{'a'}, 2)

	n := ws.Delete(2, 3)
	testhelpers.AssertString(t, "", ws.String())
	testhelpers.AssertInt(t, 0, n)
}
示例#20
0
func Test_Type(t *testing.T) {
	mock := &mockttyfd{make([][]byte, 0, 10)}
	tp := New(mock, Makecho())

	e := &acme.Event{Nr: len("hello"), Text: []byte("hello")}
	tp.Type(e)

	testhelpers.AssertString(t, "hello", string(tp.Typing))
}
示例#21
0
func Test_SendtypeOnechar(t *testing.T) {
	mock := &mockttyfd{make([][]byte, 0, 10)}
	tp := New(mock, Makecho())

	tp.addtype([]byte("h"), 0, true)
	tp.Sendtype()

	testhelpers.AssertInt(t, 0, len(mock.writes))
	testhelpers.AssertString(t, "h", string(tp.Typing))
}
示例#22
0
// Positions 0, 1 are before the buffer.
// Position 2 is the end of the buffer.
func Test_Addtyping(t *testing.T) {
	ws := New()
	ws.Move(2)

	testhelpers.AssertBool(t, true, ws.Beforeslice(0))
	testhelpers.AssertBool(t, true, ws.Beforeslice(1))

	ws.Addtyping([]byte{'a'}, 2)
	testhelpers.AssertString(t, "a", ws.String())

	testhelpers.AssertBool(t, true, ws.Beforeslice(1))

	testhelpers.AssertBool(t, true, ws.Inslice(2))
	testhelpers.AssertBool(t, true, ws.Inslice(3))
	testhelpers.AssertBool(t, false, ws.Inslice(4))

	testhelpers.AssertInt(t, 2, ws.Offset)
	testhelpers.AssertBool(t, true, ws.Afterslice(2, 0))
	testhelpers.AssertBool(t, false, ws.Afterslice(1, 1))

	ws.Addtyping([]byte{'b'}, 3)
	testhelpers.AssertString(t, "ab", ws.String())
	testhelpers.AssertBool(t, true, ws.Inslice(4))
	testhelpers.AssertBool(t, false, ws.Inslice(5))

	p, q := ws.Extent()
	testhelpers.AssertInt(t, 2, p)
	testhelpers.AssertInt(t, 4, q)

	ws.Addtyping([]byte{'c'}, 4)
	testhelpers.AssertString(t, "abc", ws.String())
	testhelpers.AssertInt(t, len("abc"), ws.Ntyper())

	testhelpers.AssertInt(t, 2, ws.Offset)
	ws.Addtyping([]byte{'X'}, 2)
	testhelpers.AssertString(t, "Xabc", ws.String())
	testhelpers.AssertInt(t, len("Xabc"), ws.Ntyper())

	ws.Addtyping([]byte{'Y'}, 3)
	testhelpers.AssertString(t, "XYabc", ws.String())

}
示例#23
0
func Test_Cancel_CharacterChange(t *testing.T) {
	echo := Makecho()
	echo.echoed([]byte("hello"))

	s := []byte("helloworld")
	r := echo.Cancel(s)
	testhelpers.AssertString(t, "world", string(r))
	if echo.oldest != nil {
		t.Error("Test_Cancel_Subword: failed to reset oldest: ", string(echo.oldest))
	}
}
示例#24
0
func Test_Cancel_Backspace(t *testing.T) {
	echo := Makecho()
	echo.echoed([]byte("helloworld"))

	s := []byte("hello\x08 \x08worldyay")
	r := echo.Cancel(s)
	testhelpers.AssertString(t, "yay", string(r))
	if echo.oldest != nil {
		t.Error("Test_Cancel_Subword: failed to reset oldest")
	}
}
示例#25
0
func Test_Cancel_Subword(t *testing.T) {
	echo := Makecho()
	echo.echoed([]byte("hello\n"))

	s := []byte("hello\r\nworld")
	r := echo.Cancel(s)
	testhelpers.AssertString(t, "world", string(r))
	if echo.oldest != nil {
		t.Errorf("Test_Cancel_Subword: failed to reset oldest: <%s>", string(echo.oldest))
	}
}
示例#26
0
func Test_ValidBaseName(t *testing.T) {
	testhelpers.AssertString(t, "foo", ValidBaseName([]string{"foo"}))
	testhelpers.AssertString(t, "foo-bar", ValidBaseName([]string{"foo", "bar"}))
	testhelpers.AssertString(t, "fo,o-b-ar-,", ValidBaseName([]string{"fo/o", "b ar", "#"}))
	testhelpers.AssertString(t, "fo-o-bar", ValidBaseName([]string{"fo	o", "bar"}))
	testhelpers.AssertString(t, "one-two-three", ValidBaseName([]string{"one", "two", "three"}))
	testhelpers.AssertString(t, "2012,12,12", ValidBaseName([]string{"2012/12/12"}))
}
示例#27
0
func Test_EchoedType(t *testing.T) {
	echo := Makecho()
	s := []byte("hello")

	testhelpers.AssertInt(t, 0, len(echo.childbound))

	echo.echoed(s)
	s[0] = 'H'

	testhelpers.AssertInt(t, 1, len(echo.childbound))
	r := <-echo.childbound
	testhelpers.AssertString(t, "hello", string(r))
	testhelpers.AssertInt(t, 0, len(echo.childbound))
}
示例#28
0
func Test_Labelcommand_basic(t *testing.T) {
	b, r := Labelcommand([]byte{})
	if r != nil {
		t.Error("empty buf should have no label")
	}
	if len(b) != 0 {
		t.Error("empty buf should still be empty")
	}

	b, r = Labelcommand([]byte("h"))
	if r != nil {
		t.Error("simple buf should have no label")
	}
	testhelpers.AssertString(t, "h", string(b))
}
示例#29
0
func Test_Addtyping_AfterPanic(t *testing.T) {
	ws := New()
	ws.Move(2)

	defer func() {
		if e := recover(); e != nil {
			s := e.(string)
			testhelpers.AssertString(t, "p (3) !in [ws.Offset: 2, ws.Offset + len: 2)", s)
		} else {
			t.Fail()
		}
	}()

	ws.Addtyping([]byte{'c'}, 3)
}
示例#30
0
func Test_JsonDate(t *testing.T) {
	statdate, _ := ParseDateUnix("1999/03/21 17:00:00")
	tagdate, _ := ParseDateUnix("2012/03/19 06:51:15")
	SetPathForContent("/url-here")

	datas := []tEdMd{
		{nil, json1, MetaData{"1.md", statdate, never, "What I want 0", false, []string{}, map[string]string{}}},
		{nil, json2, MetaData{"2.md", statdate, tagdate, "What I want 0", true, []string{}, map[string]string{}}}}

	for _, m := range datas {
		b, e := m.md.MarshalJSON()
		if m.err != e {
			t.Errorf("error value wrong")
		}
		testhelpers.AssertString(t, m.result, string(b))
	}
}