Esempio n. 1
0
func TestWithAllTags(t *testing.T) {
	grnl := New()

	entryA := entry.New()
	entryA.Tags = []string{"a", "c"}
	grnl.Add(*entryA)

	entryB := entry.New()
	entryB.Tags = []string{"a", "b"}
	grnl.Add(*entryB)

	entryC := entry.New()
	entryC.Tags = []string{"b", "c"}
	grnl.Add(*entryC)

	if len(grnl.WithAllTags([]string{"a", "b"}).Query()) != 1 {
		t.Errorf("WithAllTags() should include entries tagged with the all given tags")
	}
}
Esempio n. 2
0
func TestWithSomeTags(t *testing.T) {
	grnl := New()

	entryA := entry.New()
	entryA.Tags = []string{"a", "c"}
	grnl.Add(*entryA)

	entryB := entry.New()
	entryB.Tags = []string{"a", "b"}
	grnl.Add(*entryB)

	entryC := entry.New()
	entryC.Tags = []string{"b", "c"}
	grnl.Add(*entryC)

	if len(grnl.WithSomeTags([]string{"a"}).Query()) != 2 {
		t.Errorf("WithSomeTags() should include entries tagged with the given value")
	}

	if len(grnl.WithSomeTags([]string{"a", "b"}).Query()) != 3 {
		t.Errorf("WithSomeTags() should include entries tagged with any of the given values")
	}
}
Esempio n. 3
0
File: add.go Progetto: jzorn/grnl
			if editorInputErr != nil {
				fmt.Println(editorInputErr)
				os.Exit(1)
			}
			input = string(editorInput[:])
		} else {
			input = strings.Join(args, " ")
		}

		if input == "" {
			fmt.Println("Nothing saved")
			os.Exit(0)
		}

		newEntry := entry.New()
		newEntry.Parse(input, dateFormat)

		dbContents, readFileErr := ioutil.ReadFile(db)
		if readFileErr != nil {
			if !os.IsNotExist(readFileErr) {
				fmt.Println(readFileErr)
				os.Exit(1)
			}
		}

		grnl, err := journal.FromJson(dbContents)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}