From 0b1e9f4b51b704f53df6fcfc60a5d30fae01faef Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Sat, 17 Oct 2015 15:24:17 -0400 Subject: [PATCH] src: new program `test_highlight` Signed-off-by: Jean Privat --- src/test_highlight.nit | 74 ++++++++++ tests/nitcg.skip | 1 + tests/sav/test_highlight.res | 2 + tests/sav/test_highlight_args1.res | 279 ++++++++++++++++++++++++++++++++++++ tests/test_highlight.args | 1 + 5 files changed, 357 insertions(+) create mode 100644 src/test_highlight.nit create mode 100644 tests/sav/test_highlight.res create mode 100644 tests/sav/test_highlight_args1.res create mode 100644 tests/test_highlight.args diff --git a/src/test_highlight.nit b/src/test_highlight.nit new file mode 100644 index 0000000..96d0835 --- /dev/null +++ b/src/test_highlight.nit @@ -0,0 +1,74 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Program used to test the Nit highlighter +module test_highlight + +import highlight +import test_phase + +redef fun do_work(mainmodule, mmodules, mb) +do + var v = new HighlightVisitor + print """ + + + {{{v.head_content}}} + + """ + + for mm in mmodules do for cd in mm.mclassdefs do for pd in cd.mpropdefs do + var n = mb.mpropdef2node(pd) + if not n isa APropdef then continue + var hl = new HighlightVisitor + hl.enter_visit(n) + print "

{pd.full_name}

" + printn "
"
+		hl.html.write_to(stdout)
+		print "
" + end + + # Some random nodes + var thlv = new THLVisitor + for mm in mmodules do + var n = mb.mmodule2node(mm) + thlv.enter_visit(n) + end + + print v.foot_content + print "" +end + +class THLVisitor + super Visitor + var seen = new HashSet[String] + redef fun visit(n) + do + var cn = n.class_name + if not seen.has(cn) then + seen.add cn + + var hl = new HighlightVisitor + hl.enter_visit(n) + print "

AST node: {cn} at {n.location}

" + printn "
"
+			hl.html.write_to(stdout)
+			print "
" + end + + n.visit_all(self) + end +end diff --git a/tests/nitcg.skip b/tests/nitcg.skip index c490ae2..d8429ff 100644 --- a/tests/nitcg.skip +++ b/tests/nitcg.skip @@ -3,4 +3,5 @@ test_docdown test_neo test_phase test_parser +test_highlight ^nit diff --git a/tests/sav/test_highlight.res b/tests/sav/test_highlight.res new file mode 100644 index 0000000..fd8dbb5 --- /dev/null +++ b/tests/sav/test_highlight.res @@ -0,0 +1,2 @@ +Usage: [OPTION]... ... +Use --help for help diff --git a/tests/sav/test_highlight_args1.res b/tests/sav/test_highlight_args1.res new file mode 100644 index 0000000..7c2989f --- /dev/null +++ b/tests/sav/test_highlight_args1.res @@ -0,0 +1,279 @@ + + + + + + + +

base_simple3#Int#output

+
	fun output is intern
+

base_simple3#A#Object::init

+
	init do 5.output
+

base_simple3#A#run

+
	fun run do 6.output
+

base_simple3#B#_val

+
	var val: Int
+

base_simple3#B#val

+
	var val: Int
+

base_simple3#B#val=

+
	var val: Int
+

base_simple3#B#init

+
	init(v: Int)
+	do
+		7.output
+		self.val = v
+	end
+

base_simple3#B#run

+
	fun run do val.output
+

base_simple3#C#_val1

+
	var val1: Int
+

base_simple3#C#val1

+
	var val1: Int
+

base_simple3#C#val1=

+
	var val1: Int
+

base_simple3#C#_val2

+
	var val2: Int = 10
+

base_simple3#C#val2

+
	var val2: Int = 10
+

base_simple3#C#val2=

+
	var val2: Int = 10
+

base_simple3#Sys#foo

+
fun foo do 2.output
+

base_simple3#Sys#bar

+
fun bar(i: Int) do i.output
+

base_simple3#Sys#baz

+
fun baz: Int do return 4
+

base_simple3#Sys#main

+
1.output
+foo
+bar(3)
+baz.output
+
+var a = new A
+a.run
+
+var b = new B(8)
+b.run
+
+var c = new C(9)
+c.val1.output
+c.val2.output
+

AST node: AModule at base_simple3.nit:17,1--66,13

+
import end
+
+interface Object
+end
+
+enum Bool
+end
+
+enum Int
+	fun output is intern
+end
+
+class A
+	init do 5.output
+	fun run do 6.output
+end
+
+class B
+	var val: Int
+	init(v: Int)
+	do
+		7.output
+		self.val = v
+	end
+	fun run do val.output
+end
+
+class C
+	var val1: Int
+	var val2: Int = 10
+end
+
+fun foo do 2.output
+fun bar(i: Int) do i.output
+fun baz: Int do return 4
+
+1.output
+foo
+bar(3)
+baz.output
+
+var a = new A
+a.run
+
+var b = new B(8)
+b.run
+
+var c = new C(9)
+c.val1.output
+c.val2.output
+

AST node: ANoImport at base_simple3.nit:17,1--10

+
import end
+

AST node: APublicVisibility at base_simple3.nit:17,1

+
+

AST node: TKwimport at base_simple3.nit:17,1--6

+
import
+

AST node: TKwend at base_simple3.nit:17,8--10

+
 end
+

AST node: AStdClassdef at base_simple3.nit:19,1--20,3

+
interface Object
+end
+

AST node: AInterfaceClasskind at base_simple3.nit:19,1--9

+
interface
+

AST node: TKwinterface at base_simple3.nit:19,1--9

+
interface
+

AST node: TClassid at base_simple3.nit:19,11--16

+
 Object
+

AST node: AEnumClasskind at base_simple3.nit:22,1--4

+
enum
+

AST node: TKwenum at base_simple3.nit:22,1--4

+
enum
+

AST node: AMethPropdef at base_simple3.nit:26,2--21

+
	fun output is intern
+

AST node: TKwmeth at base_simple3.nit:26,2--4

+
	fun
+

AST node: AIdMethid at base_simple3.nit:26,6--11

+
 output
+

AST node: TId at base_simple3.nit:26,6--11

+
 output
+

AST node: ASignature at base_simple3.nit:26,13

+
+

AST node: AAnnotations at base_simple3.nit:26,13--21

+
 is intern
+

AST node: TKwis at base_simple3.nit:26,13--14

+
 is
+

AST node: AAnnotation at base_simple3.nit:26,16--21

+
 intern
+

AST node: AIdAtid at base_simple3.nit:26,16--21

+
 intern
+

AST node: AConcreteClasskind at base_simple3.nit:29,1--5

+
class
+

AST node: TKwclass at base_simple3.nit:29,1--5

+
class
+

AST node: TKwinit at base_simple3.nit:30,2--5

+
	init
+

AST node: TKwdo at base_simple3.nit:30,7--8

+
 do
+

AST node: ACallExpr at base_simple3.nit:30,10--17

+
 5.output
+

AST node: AIntegerExpr at base_simple3.nit:30,10

+
 5
+

AST node: TInteger at base_simple3.nit:30,10

+
 5
+

AST node: AQid at base_simple3.nit:30,12--17

+
output
+

AST node: AListExprs at base_simple3.nit:30,17

+
+

AST node: AAttrPropdef at base_simple3.nit:35,2--13

+
	var val: Int
+

AST node: TKwvar at base_simple3.nit:35,2--4

+
	var
+

AST node: AType at base_simple3.nit:35,11--13

+
 Int
+

AST node: TOpar at base_simple3.nit:36,6

+
(
+

AST node: AParam at base_simple3.nit:36,7--12

+
v: Int
+

AST node: TCpar at base_simple3.nit:36,13

+
)
+

AST node: ABlockExpr at base_simple3.nit:38,3--40,4

+
		7.output
+		self.val = v
+	end
+

AST node: ACallAssignExpr at base_simple3.nit:39,3--14

+
		self.val = v
+

AST node: ASelfExpr at base_simple3.nit:39,3--6

+
		self
+

AST node: TKwself at base_simple3.nit:39,3--6

+
		self
+

AST node: TAssign at base_simple3.nit:39,12

+
 =
+

AST node: AVarExpr at base_simple3.nit:39,14

+
 v
+

AST node: AImplicitSelfExpr at base_simple3.nit:41,13

+
+

AST node: ATopClassdef at base_simple3.nit:49,1--19

+
fun foo do 2.output
+

AST node: AReturnExpr at base_simple3.nit:51,17--24

+
 return 4
+

AST node: TKwreturn at base_simple3.nit:51,17--22

+
 return
+

AST node: AMainClassdef at base_simple3.nit:53,1--66,13

+
1.output
+foo
+bar(3)
+baz.output
+
+var a = new A
+a.run
+
+var b = new B(8)
+b.run
+
+var c = new C(9)
+c.val1.output
+c.val2.output
+

AST node: AMainMethPropdef at base_simple3.nit:53,1--66,13

+
1.output
+foo
+bar(3)
+baz.output
+
+var a = new A
+a.run
+
+var b = new B(8)
+b.run
+
+var c = new C(9)
+c.val1.output
+c.val2.output
+

AST node: AParExprs at base_simple3.nit:55,4--6

+
(3)
+

AST node: AVardeclExpr at base_simple3.nit:58,1--13

+
var a = new A
+

AST node: ANewExpr at base_simple3.nit:58,9--13

+
 new A
+

AST node: TKwnew at base_simple3.nit:58,9--11

+
 new
+ + + + diff --git a/tests/test_highlight.args b/tests/test_highlight.args new file mode 100644 index 0000000..5f3aa2c --- /dev/null +++ b/tests/test_highlight.args @@ -0,0 +1 @@ +base_simple3.nit -- 1.7.9.5