Skip to content

Commit c2aa3bc

Browse files
authored
Add project unit test cases (#133)
Add project unit test cases (#133)
1 parent 7c352e2 commit c2aa3bc

8 files changed

+405
-22
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
; random sample file
2+
3+
(defun sampleFunc (x y / a b c d)
4+
(setq a (list 1 2 3 4) ; does this screw it all up?
5+
d (setq b 0)
6+
b (mapcar '+ a))
7+
(foreach x a
8+
(setq d (1+ d))
9+
)
10+
11+
(defun SymPtrOnly ()
12+
(setq gv 32)
13+
)
14+
15+
(defun c (a b / q)
16+
(defun q (r j / z)
17+
(setq z (* r j))
18+
)
19+
20+
(q a b)
21+
)
22+
)
23+
24+
25+
(setq some "random" ; does this trip?
26+
global (list "variables" "to" "test")
27+
with (vl-sort '(lambda(a b) (setq c (< a b))) global)
28+
)
29+
30+
(foreach rando global
31+
(setq some (strcat some " " rando))
32+
)
33+
34+
35+
36+
(defun DumpPidMarkups (/ path pdfList pdfMarkups lineList compList equpList chckList textList resp contractDrawings downloadPdfs downloadPath badFiles noMarkups)
37+
38+
(defun collectMarkups ( file / pchckList pcompList pequpList plineList ptextList markups fixAnno ret )
39+
(setq ret nil)
40+
(if (not (vl-catch-all-error-p (setq markups (vl-catch-all-apply 'NS:XfiniumPDF:GetAnnotations (list file 1))))) ; Hard code page 1
41+
(if (> (length markups) 0)
42+
(progn
43+
(setq markups (vl-remove-if '(lambda (a) (or (/= (type a) 'LIST) (/= (strcase (nth 3 a)) "FREETEXT") (null (nth 5 a)) (= (nth 5 a) ""))) markups))
44+
(setq markups (mapcar '(lambda (a) (list (vl-filename-base file) (nth 4 a) (nth 5 a) (nth 6 a))) markups))
45+
(if (> (length markups) 0)
46+
(progn
47+
(foreach anno markups
48+
(setq fixAnno (mapcar '(lambda (l) (if (= (type l) 'STR) (acet-str-replace "\r" "-" (vl-string-trim " " (vl-string-trim (chr 9) l))) l)) anno))
49+
(cond
50+
((vl-string-search "LINENUMBER" (strcase (nth 1 fixAnno)))
51+
(setq plineList (cons fixAnno plineList)))
52+
((vl-string-search "COMPONENT" (strcase (nth 1 fixAnno)))
53+
(setq pcompList (cons fixAnno pcompList)))
54+
((vl-string-search "EQUIPMENT" (strcase (nth 1 fixAnno)))
55+
(setq pequpList (cons fixAnno pequpList)))
56+
((and (null (vl-string-search "NOT IN SCOPE" (nth 2 fixAnno)))(>= (- (strlen (nth 2 fixAnno)) (strlen (acet-str-replace "-" "" (nth 2 fixAnno)))) 3))
57+
(setq pchckList (cons fixAnno pchckList)))
58+
(t
59+
(setq ptextList (cons fixAnno ptextList)))
60+
)
61+
)
62+
(setq ret (list plineList pcompList pequpList pchckList ptextList))
63+
)
64+
)
65+
)
66+
)
67+
(setq ret (vl-filename-base file))
68+
)
69+
ret
70+
)
71+
72+
(defun getPdfList ( pth / retList )
73+
(setq retList (cadr (NS:ACAD:FilePicker "Select P&IDs to export markups" "Select files" GV:ProjPath "*.pdf")))
74+
(cond
75+
((null retList) (exit))
76+
((and (vl-consp retList) (= (length retList) 1) (= (car retList) ""))
77+
(setq retList getPdfList))
78+
((and (vl-consp retList) (> (length retList) 1) (vl-every 'findfile retList))
79+
(terpri)
80+
(prompt (strcat (itoa (length retList)) " PDFs selected for processing")))
81+
)
82+
retList
83+
)
84+
85+
86+
(if (null GV:ProjIni) (progn (NS:ACAD:MessageBox *GV:ProjIni* "Project.ini error" 0 16)(exit)))
87+
88+
(setq resp (car (NS:ACAD:MessageBox "Do you want to download drawings?" "P&ID Download and Export" 3 32)))
89+
(cond
90+
((= resp 2) ; Cancel
91+
(terpri)
92+
(prompt "P&ID Markup Export Terminated")
93+
(exit)
94+
)
95+
((= resp 6) ; Yes
96+
(setq contractDrawings (vl-catch-all-apply 'NS:Sharepoint:Read (list t GV:ExePath GV:ProjUrl "Contract Drawings" "ID" "Name")))
97+
(if (vl-catch-all-error-p contractDrawings) (progn (alert "Error reading from Sharepoint") (exit)))
98+
(setq contractDrawings (vl-remove-if '(lambda (d) (null (vl-string-search ".pdf" (car d)))) (mapcar 'reverse contractDrawings))
99+
downloadPdfs (cadr (NS:ACAD:ListBox "Select PDFs to Download" "Download Drawings" (acad_strlsort (mapcar 'car contractDrawings)) t)))
100+
(if (null downloadPdfs) (exit))
101+
(setq downloadPath (caadr (NS:ACAD:DirPicker "Select Download Path" "Download files" GV:ProjPath)))
102+
(if (null downloadPath) (exit))
103+
(foreach pdf downloadPdfs
104+
(setq downloadIds (cons (cadr (assoc pdf contractDrawings)) downloadIds))
105+
)
106+
(NS:SharePoint:Download GV:ExePath (cadr(assoc "SITE" GV:ProjIni)) "Contract Drawings" "ID" (mapcar 'itoa downloadIds) downloadPath)
107+
(setq defaultPath downloadPath)
108+
)
109+
((= resp 7) ; No
110+
(setq defaultPath GV:ProjPath))
111+
)
112+
(setq pdfList (getPdfList defaultPath))
113+
(if (and pdfList (> (length pdfList) 0))
114+
(foreach pdf pdfList
115+
(setq pdfMarkups (collectMarkups pdf))
116+
(cond
117+
((null pdfMarkups)
118+
(setq noMarkups (cons (vl-filename-base pdf) noMarkups)))
119+
((= (type pdfMarkups) 'STR)
120+
(setq badFiles (cons pdfMarkups badFiles)))
121+
((listp pdfMarkups)
122+
(if (nth 0 pdfMarkups)
123+
(setq lineList (append (nth 0 pdfMarkups) lineList)))
124+
(if (nth 1 pdfMarkups)
125+
(setq compList (append (nth 1 pdfMarkups) compList)))
126+
(if (nth 2 pdfMarkups)
127+
(setq equpList (append (nth 2 pdfMarkups) equpList)))
128+
(if (nth 3 pdfMarkups)
129+
(setq chckList (append (nth 3 pdfMarkups) chckList)))
130+
(if (nth 4 pdfMarkups)
131+
(setq textList (append (nth 4 pdfMarkups) textList))))
132+
)
133+
)
134+
)
135+
(if lineList (IO:WriteLines (cons (list "Page" "Subject" "LineTag" "Author") lineList) (strcat (vl-filename-directory (car pdfList)) "\\Linenumber List.csv")))
136+
(if compList (IO:WriteLines (cons (list "Page" "Subject" "ComponentTag" "Author") compList) (strcat (vl-filename-directory (car pdfList)) "\\Components List.csv")))
137+
(if equpList (IO:WriteLines (cons (list "Page" "Subject" "EquipmentTag" "Author") equpList) (strcat (vl-filename-directory (car pdfList)) "\\Equipment List.csv")))
138+
(if chckList (IO:WriteLines (cons (list "Page" "Subject" "Contents" "Author") chckList) (strcat (vl-filename-directory (car pdfList)) "\\Review Required List.csv")))
139+
(if textList (IO:WriteLines (cons (list "Page" "Subject" "Contents" "Author") textList) (strcat (vl-filename-directory (car pdfList)) "\\FreeText List.csv")))
140+
(if badFiles (NS:ACAD:ListBox "Error reading the following files" "File Errors" (acad_strlsort badFiles) t))
141+
(if noMarkups (NS:ACAD:ListBox "There were no markups on the following files" "No markups" (acad_strlsort noMarkups) t))
142+
(terpri)
143+
(prompt "P&ID Markup Export Complete")
144+
(princ)
145+
)
146+
147+
148+
(defun doStuff (pth / retList)
149+
(setq retList (cadr (NS:ACAD:FilePicker "Select P&IDs to export markups" "Select files" GV:ProjPath "*.pdf" )))
150+
(cond
151+
((null retList) (exit))
152+
((and (vl-consp retList) (= (length retList) 1) (= (car retList) ""))
153+
(setq retList getPdfList)
154+
)
155+
((and (vl-consp retList) (> (length retList) 1) (vl-every 'findfile retList))
156+
(terpri)
157+
(prompt (strcat (itoa (length retList)) " PDFs selected for processing"))
158+
)
159+
)
160+
retList
161+
)
162+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
;;; VLisp project file [V2.0] project_no_lisp_file saved to:[d:\2\AutoLispExt\test_case] at:[4/13/2021]
2+
(VLISP-PROJECT-LIST
3+
:NAME
4+
project_no_lisp_file
5+
:OWN-LIST
6+
nil
7+
:FAS-DIRECTORY
8+
nil
9+
:TMP-DIRECTORY
10+
nil
11+
:PROJECT-KEYS
12+
(:BUILD (:standard))
13+
:CONTEXT-ID
14+
:AUTOLISP
15+
)
16+
;;; EOF
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
;;; VLisp project file [V2.0] project_test_file saved to:[d:\github\AutoLispExt\test_case] at:[6/16/2020]
2+
(VLISP-PROJECT-LIST
3+
:NAME
4+
project_test_file
5+
:OWN-LIST
6+
("test_remove")
7+
:FAS-DIRECTORY
8+
nil
9+
:TMP-DIRECTORY
10+
nil
11+
:PROJECT-KEYS
12+
(:BUILD (:standard))
13+
:CONTEXT-ID
14+
:AUTOLISP
15+
)
16+
;;; EOF
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
(print "this 55 is a test22")
3+
(command "-layer")

extension/src/test/suite/DocumentContainer.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { LispParser } from '../../format/parser';
66
import { Sexpression, LispContainer } from '../../format/sexpression';
77
import { ReadonlyDocument } from '../../project/readOnlyDocument';
88

9-
let assert = chai.assert;
10-
let lispFileTest = path.join(__dirname + "/../../../test_case/pdfMarkups.lsp");
9+
var assert = require('chai').assert;
10+
let prefixpath = __filename + "/../../../../extension/src/test/SourceFile/test_case/";
11+
let lispFileTest = path.join(prefixpath + "pdfMarkups.lsp");
1112

1213
suite("LispParser.DocumentContainer Tests", function () {
1314
test("Original atomsForest vs DocumentContainer", function () {

extension/src/test/suite/LispContainer.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { ILispFragment, LispContainer } from '../../format/sexpression';
55
import { ReadonlyDocument } from '../../project/readOnlyDocument';
66
import { LispParser } from '../../format/parser';
77

8-
let lispFileTest = path.join(__dirname + "/../../../test_case/pdfMarkups.lsp");
8+
let prefixpath = __filename + "/../../../../extension/src/test/SourceFile/test_case/";
9+
let lispFileTest = path.join(prefixpath + "pdfMarkups.lsp");
10+
// let project_path = path.join(__dirname + "\\..\\..\\..\\test_case\\pdfMarkups.lsp");
911
let pos1: Position = new Position(98, 100); // based on line: " downloadPdfs (cadr (NS:ACAD:ListBox "Select PDFs to Download" "Download Drawings" (acad_strlsort (mapcar 'car contractDrawings)) t)))"
1012
let pos2: Position = new Position(100, 100); // based on line: " (setq downloadPath (caadr (NS:ACAD:DirPicker "Select Download Path" "Download files" GV:ProjPath)))"
1113

extension/src/test/suite/ReadonlyDocument.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { TextDocument } from 'vscode';
33
import { ReadonlyDocument } from '../../project/readOnlyDocument';
44

55
var assert = require('chai').assert;
6-
let lispFileTest = path.join(__dirname + "/../../../test_case/pdfMarkups.lsp");
6+
let prefixpath = __filename + "/../../../../extension/src/test/SourceFile/test_case/";
7+
let lispFileTest = path.join(prefixpath + "pdfMarkups.lsp");
78

89

910
suite("ReadonlyDocument Tests", function () {

0 commit comments

Comments
 (0)