Fixed ugly inheritance issue with Issue and FileIssue.

Added Filter unit tests.
This commit is contained in:
Jonathan Bernard 2010-02-21 15:43:24 -06:00
parent 7ff8806544
commit ce35e14694
9 changed files with 312 additions and 74 deletions

View File

@ -1,9 +1,9 @@
#Sat Feb 20 22:25:08 CST 2010 #Sun Feb 21 15:42:19 CST 2010
build.dir=build build.dir=build
src.dir=src src.dir=src
lib.shared.dir=../shared-libs lib.shared.dir=../shared-libs
test.dir=test test.dir=test
build.number=53 build.number=64
expected.application.version=1.1.2 expected.application.version=1.1.2
lib.dir=lib lib.dir=lib
release.dir=release release.dir=release

Binary file not shown.

View File

@ -33,15 +33,19 @@ if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
endif endif
set shortmess=aoO set shortmess=aoO
badd +1 build.xml badd +1 build.xml
badd +0 project.properties badd +1 project.properties
badd +1 src/com/jdbernard/pit/Category.groovy badd +1 src/com/jdbernard/pit/Category.groovy
badd +0 test/com/jdbernard/pit/CategoryTest.groovy badd +1 test/com/jdbernard/pit/CategoryTest.groovy
badd +1 src/com/jdbernard/pit/Filter.groovy badd +1 src/com/jdbernard/pit/Filter.groovy
badd +0 test/com/jdbernard/pit/FilterTest.groovy badd +1 test/com/jdbernard/pit/FilterTest.groovy
badd +1 src/com/jdbernard/pit/Issue.groovy badd +1 src/com/jdbernard/pit/Issue.groovy
badd +0 test/com/jdbernard/pit/IssueTest.groovy badd +1 test/com/jdbernard/pit/IssueTest.groovy
badd +1 src/com/jdbernard/pit/Project.groovy badd +6 src/com/jdbernard/pit/Project.groovy
badd +0 test/com/jdbernard/pit/ProjectTest.groovy badd +1 test/com/jdbernard/pit/ProjectTest.groovy
badd +1 src/com/jdbernard/pit/FileIssue.groovy
badd +0 test/com/jdbernard/pit/FileIssueTest.groovy
badd +1 src/com/jdbernard/pit/FileProject.groovy
badd +0 test/com/jdbernard/pit/FileProjectTest.groovy
args build.xml args build.xml
edit build.xml edit build.xml
set splitbelow splitright set splitbelow splitright
@ -151,7 +155,7 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 1 - ((0 * winheight(0) + 28) / 57) let s:l = 1 - ((0 * winheight(0) + 39) / 78)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
@ -255,14 +259,13 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 1 - ((0 * winheight(0) + 28) / 57) let s:l = 1 - ((0 * winheight(0) + 39) / 78)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
1 1
normal! 0 normal! 0
wincmd w wincmd w
2wincmd w
exe 'vert 1resize ' . ((&columns * 91 + 91) / 182) exe 'vert 1resize ' . ((&columns * 91 + 91) / 182)
exe 'vert 2resize ' . ((&columns * 90 + 91) / 182) exe 'vert 2resize ' . ((&columns * 90 + 91) / 182)
tabedit src/com/jdbernard/pit/Category.groovy tabedit src/com/jdbernard/pit/Category.groovy
@ -373,7 +376,7 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 1 - ((0 * winheight(0) + 28) / 57) let s:l = 1 - ((0 * winheight(0) + 39) / 78)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
@ -477,14 +480,13 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 1 - ((0 * winheight(0) + 28) / 57) let s:l = 1 - ((0 * winheight(0) + 39) / 78)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
1 1
normal! 0 normal! 0
wincmd w wincmd w
2wincmd w
exe 'vert 1resize ' . ((&columns * 91 + 91) / 182) exe 'vert 1resize ' . ((&columns * 91 + 91) / 182)
exe 'vert 2resize ' . ((&columns * 90 + 91) / 182) exe 'vert 2resize ' . ((&columns * 90 + 91) / 182)
tabedit src/com/jdbernard/pit/Filter.groovy tabedit src/com/jdbernard/pit/Filter.groovy
@ -595,7 +597,7 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 1 - ((0 * winheight(0) + 28) / 57) let s:l = 1 - ((0 * winheight(0) + 39) / 78)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
@ -699,14 +701,13 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 1 - ((0 * winheight(0) + 28) / 57) let s:l = 103 - ((26 * winheight(0) + 39) / 78)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
1 103
normal! 0 normal! 04l
wincmd w wincmd w
2wincmd w
exe 'vert 1resize ' . ((&columns * 91 + 91) / 182) exe 'vert 1resize ' . ((&columns * 91 + 91) / 182)
exe 'vert 2resize ' . ((&columns * 90 + 91) / 182) exe 'vert 2resize ' . ((&columns * 90 + 91) / 182)
tabedit src/com/jdbernard/pit/Issue.groovy tabedit src/com/jdbernard/pit/Issue.groovy
@ -817,7 +818,7 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 1 - ((0 * winheight(0) + 28) / 57) let s:l = 1 - ((0 * winheight(0) + 39) / 78)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
@ -825,7 +826,7 @@ normal! zt
normal! 0 normal! 0
wincmd w wincmd w
argglobal argglobal
edit test/com/jdbernard/pit/IssueTest.groovy edit src/com/jdbernard/pit/Project.groovy
setlocal keymap= setlocal keymap=
setlocal noarabic setlocal noarabic
setlocal autoindent setlocal autoindent
@ -921,17 +922,16 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 1 - ((0 * winheight(0) + 28) / 57) let s:l = 1 - ((0 * winheight(0) + 39) / 78)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
1 1
normal! 0 normal! 0
wincmd w wincmd w
2wincmd w
exe 'vert 1resize ' . ((&columns * 91 + 91) / 182) exe 'vert 1resize ' . ((&columns * 91 + 91) / 182)
exe 'vert 2resize ' . ((&columns * 90 + 91) / 182) exe 'vert 2resize ' . ((&columns * 90 + 91) / 182)
tabedit src/com/jdbernard/pit/Project.groovy tabedit src/com/jdbernard/pit/FileIssue.groovy
set splitbelow splitright set splitbelow splitright
wincmd _ | wincmd | wincmd _ | wincmd |
vsplit vsplit
@ -1039,15 +1039,15 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 1 - ((0 * winheight(0) + 28) / 57) let s:l = 9 - ((8 * winheight(0) + 39) / 78)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
1 9
normal! 0 normal! 010l
wincmd w wincmd w
argglobal argglobal
edit test/com/jdbernard/pit/ProjectTest.groovy edit test/com/jdbernard/pit/FileIssueTest.groovy
setlocal keymap= setlocal keymap=
setlocal noarabic setlocal noarabic
setlocal autoindent setlocal autoindent
@ -1143,17 +1143,238 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 1 - ((0 * winheight(0) + 28) / 57) let s:l = 1 - ((0 * winheight(0) + 39) / 78)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
1 1
normal! 0 normal! 0
wincmd w wincmd w
exe 'vert 1resize ' . ((&columns * 91 + 91) / 182)
exe 'vert 2resize ' . ((&columns * 90 + 91) / 182)
tabedit src/com/jdbernard/pit/FileProject.groovy
set splitbelow splitright
wincmd _ | wincmd |
vsplit
1wincmd h
wincmd w
set nosplitbelow
set nosplitright
wincmd t
set winheight=1 winwidth=1
exe 'vert 1resize ' . ((&columns * 91 + 91) / 182)
exe 'vert 2resize ' . ((&columns * 90 + 91) / 182)
argglobal
setlocal keymap=
setlocal noarabic
setlocal autoindent
setlocal balloonexpr=
setlocal nobinary
setlocal bufhidden=
setlocal buflisted
setlocal buftype=
setlocal nocindent
setlocal cinkeys=0{,0},0),:,0#,!^F,o,O,e
setlocal cinoptions=
setlocal cinwords=if,else,while,do,for,switch
setlocal comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-
setlocal commentstring=/*%s*/
setlocal complete=.,w,b,u,t,i
setlocal completefunc=
setlocal nocopyindent
setlocal nocursorcolumn
setlocal nocursorline
setlocal define=
setlocal dictionary=
setlocal nodiff
setlocal equalprg=
setlocal errorformat=
setlocal expandtab
if &filetype != 'groovy'
setlocal filetype=groovy
endif
setlocal foldcolumn=0
setlocal foldenable
setlocal foldexpr=0
setlocal foldignore=#
setlocal foldlevel=0
setlocal foldmarker={{{,}}}
setlocal foldmethod=manual
setlocal foldminlines=1
setlocal foldnestmax=20
setlocal foldtext=foldtext()
setlocal formatexpr=
setlocal formatoptions=tcq
setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
setlocal grepprg=
setlocal iminsert=2
setlocal imsearch=2
setlocal include=
setlocal includeexpr=
setlocal indentexpr=
setlocal indentkeys=0{,0},:,0#,!^F,o,O,e
setlocal noinfercase
setlocal iskeyword=@,48-57,_,192-255
setlocal keywordprg=
setlocal nolinebreak
setlocal nolisp
setlocal nolist
setlocal makeprg=
setlocal matchpairs=(:),{:},[:]
setlocal nomodeline
setlocal modifiable
setlocal nrformats=octal,hex
set number
setlocal number
setlocal numberwidth=4
setlocal omnifunc=
setlocal path=
setlocal nopreserveindent
setlocal nopreviewwindow
setlocal quoteescape=\\
setlocal noreadonly
setlocal norightleft
setlocal rightleftcmd=search
setlocal noscrollbind
setlocal shiftwidth=4
setlocal noshortname
setlocal nosmartindent
setlocal softtabstop=0
setlocal nospell
setlocal spellcapcheck=[.?!]\\_[\\])'\"\ \ ]\\+
setlocal spellfile=
setlocal spelllang=en
setlocal statusline=
setlocal suffixesadd=
setlocal swapfile
setlocal synmaxcol=3000
if &syntax != 'groovy'
setlocal syntax=groovy
endif
setlocal tabstop=4
setlocal tags=
setlocal textwidth=0
setlocal thesaurus=
setlocal nowinfixheight
setlocal nowinfixwidth
setlocal wrap
setlocal wrapmargin=0
silent! normal! zE
let s:l = 40 - ((39 * winheight(0) + 39) / 78)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
40
normal! 029l
wincmd w
argglobal
edit test/com/jdbernard/pit/FileProjectTest.groovy
setlocal keymap=
setlocal noarabic
setlocal autoindent
setlocal balloonexpr=
setlocal nobinary
setlocal bufhidden=
setlocal buflisted
setlocal buftype=
setlocal nocindent
setlocal cinkeys=0{,0},0),:,0#,!^F,o,O,e
setlocal cinoptions=
setlocal cinwords=if,else,while,do,for,switch
setlocal comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-
setlocal commentstring=/*%s*/
setlocal complete=.,w,b,u,t,i
setlocal completefunc=
setlocal nocopyindent
setlocal nocursorcolumn
setlocal nocursorline
setlocal define=
setlocal dictionary=
setlocal nodiff
setlocal equalprg=
setlocal errorformat=
setlocal expandtab
if &filetype != 'groovy'
setlocal filetype=groovy
endif
setlocal foldcolumn=0
setlocal foldenable
setlocal foldexpr=0
setlocal foldignore=#
setlocal foldlevel=0
setlocal foldmarker={{{,}}}
setlocal foldmethod=manual
setlocal foldminlines=1
setlocal foldnestmax=20
setlocal foldtext=foldtext()
setlocal formatexpr=
setlocal formatoptions=tcq
setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
setlocal grepprg=
setlocal iminsert=2
setlocal imsearch=2
setlocal include=
setlocal includeexpr=
setlocal indentexpr=
setlocal indentkeys=0{,0},:,0#,!^F,o,O,e
setlocal noinfercase
setlocal iskeyword=@,48-57,_,192-255
setlocal keywordprg=
setlocal nolinebreak
setlocal nolisp
setlocal nolist
setlocal makeprg=
setlocal matchpairs=(:),{:},[:]
setlocal nomodeline
setlocal modifiable
setlocal nrformats=octal,hex
set number
setlocal number
setlocal numberwidth=4
setlocal omnifunc=
setlocal path=
setlocal nopreserveindent
setlocal nopreviewwindow
setlocal quoteescape=\\
setlocal noreadonly
setlocal norightleft
setlocal rightleftcmd=search
setlocal noscrollbind
setlocal shiftwidth=4
setlocal noshortname
setlocal nosmartindent
setlocal softtabstop=0
setlocal nospell
setlocal spellcapcheck=[.?!]\\_[\\])'\"\ \ ]\\+
setlocal spellfile=
setlocal spelllang=en
setlocal statusline=
setlocal suffixesadd=
setlocal swapfile
setlocal synmaxcol=3000
if &syntax != 'groovy'
setlocal syntax=groovy
endif
setlocal tabstop=4
setlocal tags=
setlocal textwidth=0
setlocal thesaurus=
setlocal nowinfixheight
setlocal nowinfixwidth
setlocal wrap
setlocal wrapmargin=0
silent! normal! zE
let s:l = 154 - ((77 * winheight(0) + 39) / 78)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
154
normal! 0
wincmd w
2wincmd w 2wincmd w
exe 'vert 1resize ' . ((&columns * 91 + 91) / 182) exe 'vert 1resize ' . ((&columns * 91 + 91) / 182)
exe 'vert 2resize ' . ((&columns * 90 + 91) / 182) exe 'vert 2resize ' . ((&columns * 90 + 91) / 182)
tabnext 1 tabnext 6
if exists('s:wipebuf') if exists('s:wipebuf')
silent exe 'bwipe ' . s:wipebuf silent exe 'bwipe ' . s:wipebuf
endif endif

View File

@ -4,54 +4,42 @@ import java.lang.IllegalArgumentException as IAE
public class FileIssue extends Issue { public class FileIssue extends Issue {
File source protected File source
FileIssue(File file) { public FileIssue(File file) {
/* I do not like this construction, but groovy automatically super('REPLACE_ME')
* calls obj.setProperty(...) when you type obj.property = ...
* There is an exception for fields accessed withing the class
* that defines them, it does not catt eh setter/getter, but
* this exception does not extend to subclasses accessing member
* variables of their parent class. So instead of using Issue's
* default constructor and setting the id, category, and priority
* fields here, we have to let Issue's constructor initialize
* those values.*/
super((file.name =~ /(\d+)([bcft])(\d).*/)[0][1], def matcher = file.name =~ /(\d{4})([bftc])(\d).*/
Category.toCategory((file.name =~ /(\d+)([bcft])(\d).*/)[0][2]), if (!matcher) return null
(file.name =~ /(\d+)([bcft])(\d).*/)[0][3].toInteger())
//def matcher = file.name =~ /(\d{4})([bftc])(\d).*/ super.@id = matcher[0][1]
/*if (!matcher) return null super.@category = Category.toCategory(matcher[0][2])
super.@priority = matcher[0][3].toInteger()
id = matcher[0][1]
category = Category.toCategory(matcher[0][2])
priority = matcher[0][3].toInteger()*/
this.source = file this.source = file
file.withReader { title = it.readLine() }
text = file.text text = file.text
} }
void setCategory(Category c) { public void setCategory(Category c) {
super.setCategory(c) super.setCategory(c)
source.renameTo(new File(source.canonicalFile.parentFile, getFilename())) source.renameTo(new File(source.canonicalFile.parentFile, getFilename()))
} }
void setPriority(int p) { public void setPriority(int p) {
super.setPriority(p) super.setPriority(p)
source.renameTo(new File(source.canonicalFile.parentFile, getFilename())) source.renameTo(new File(source.canonicalFile.parentFile, getFilename()))
} }
String getFilename() { return makeFilename(id, category, priority) } public String getFilename() { return makeFilename(id, category, priority) }
static boolean isValidFilename(String name) { public static boolean isValidFilename(String name) {
return name ==~ /(\d+)([bcft])(\d).*/ return name ==~ /(\d+)([bcft])(\d).*/
} }
static String makeFilename(String id, Category category, int priority) { public static String makeFilename(String id, Category category,
int priority) {
// bounds check priority // bounds check priority
priority = Math.min(9, Math.max(0, priority)) priority = Math.min(9, Math.max(0, priority))

View File

@ -2,9 +2,9 @@ package com.jdbernard.pit
class FileProject extends Project { class FileProject extends Project {
File source protected File source
FileProject(File dir) { public FileProject(File dir) {
super(dir.name) super(dir.name)
if (!dir.isDirectory()) if (!dir.isDirectory())
@ -32,10 +32,6 @@ class FileProject extends Project {
} }
} }
public void rename(String newName) {
this.name = newName
}
public void setName(String name) { public void setName(String name) {
super.setName(name) super.setName(name)
source.renameTo(new File(source.canonicalFile.parentFile, name)) source.renameTo(new File(source.canonicalFile.parentFile, name))
@ -54,15 +50,21 @@ class FileProject extends Project {
id = (id.toInteger() + 1).toString().padLeft(id.length(), '0') id = (id.toInteger() + 1).toString().padLeft(id.length(), '0')
} }
def issueFile = new File(source, FileIssue.makeFilename(id, options.category, options.priority)) def issueFile = new File(source, FileIssue.makeFilename(id,
options.category, options.priority))
assert !issueFile.exists() assert !issueFile.exists()
issueFile.createNewFile() issueFile.createNewFile()
issueFile.write(options.text) issueFile.write(options.text)
return new FileIssue(issueFile) def issue = new FileIssue(issueFile)
issues[(issue.id)] = issue
return issue
} }
@Override @Override
String toString() { return name } public String toString() { return name }
} }

View File

@ -4,11 +4,10 @@ import java.lang.IllegalArgumentException as IAE
public class Issue { public class Issue {
String id protected String id
Category category protected Category category
int priority protected int priority
String title protected String text
String text
Issue(String id, Category c = Category.TASK, int p = 9) { Issue(String id, Category c = Category.TASK, int p = 9) {
this.id = id this.id = id
@ -16,15 +15,27 @@ public class Issue {
this.priority = p this.priority = p
} }
void setCategory(Category c) { public String getId() { return id; }
public Category getCategory() { return category }
public void setCategory(Category c) {
if (c == null) if (c == null)
throw new IAE("Category cannot be null.") throw new IAE("Category cannot be null.")
this.category = c this.category = c
} }
void setPriority(int p) { priority = Math.min(9, Math.max(0, p)) } public int getPriority() { return priority }
public void setPriority(int p) { priority = Math.min(9, Math.max(0, p)) }
public String getTitle() { return text.readLines()[0] }
public String getText() { return text }
public void setText(String t) { text = t }
@Override @Override
String toString() { return "${id}(${priority}): ${category} ${title}" } public String toString() { return "${id}(${priority}): ${category} ${title}" }
} }

View File

@ -2,7 +2,7 @@ package com.jdbernard.pit
public abstract class Project { public abstract class Project {
String name protected String name
Map<String, Issue> issues = [:] Map<String, Issue> issues = [:]
Map<String, Project> projects = [:] Map<String, Project> projects = [:]
@ -22,6 +22,10 @@ public abstract class Project {
c.call(p) c.call(p)
} }
public void setName(String name) { this.name = name }
public String getName() { return name }
@Override @Override
String toString() { return name } String toString() { return name }

View File

@ -136,6 +136,7 @@ class FileProjectTest {
assertEquals newIssue.text, 'A newly made bug report.\n'+ assertEquals newIssue.text, 'A newly made bug report.\n'+
'========================\n\n' + '========================\n\n' +
'Testing the Project.createNewIssue() method.' 'Testing the Project.createNewIssue() method.'
assertEquals rootProj.issues[(newIssue.id)], newIssue
//test defaults and creation of issue in an empty project //test defaults and creation of issue in an empty project
newIssue = rootProj.projects.emptyproj.createNewIssue() newIssue = rootProj.projects.emptyproj.createNewIssue()
@ -145,6 +146,9 @@ class FileProjectTest {
assertEquals newIssue.text, 'Default issue title.\n' + assertEquals newIssue.text, 'Default issue title.\n' +
'====================\n' '====================\n'
assertEquals rootProj.projects.emptyproj.issues[(newIssue.id)],
newIssue
} }
} }

View File

@ -94,4 +94,12 @@ class FilterTest {
} }
@Test void testAcceptsProjectsFilter() {
}
@Test void testCompositeFilter() {
}
} }