package pfff

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file unit_parsing_java.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
open Common

open Ast_java
module Vis = Visitor_java

open OUnit

(*****************************************************************************)
(* Unit tests *)
(*****************************************************************************)

let unittest =
  "parsing_java" >::: [

    "regression files" >:: (fun () ->
      let dir = Filename.concat Config_pfff.path "/tests/java/parsing" in
      let files = Common2.glob (spf "%s/*.java" dir) in
      files |> List.iter (fun file ->
        try
          let _ = Parse_java.parse file in
          ()
        with Parse_info.Parsing_error _ ->
          assert_failure (spf "it should correctly parse %s" file)
      )
    );

    "basic_expr_visitor" >:: (fun () ->
      let count = ref 0 in

      let vis = Vis.mk_visitor
        { Vis.default_visitor with
          Vis.kexpr = (fun (k,_) e -> match e with
          | NewClass _ -> incr count; k e
          | _ -> k e)
        } in

      let thecode = "
        class TestClass {

          public static final void main(string[] args) {
            Object x = new Runnable() {
                public void run() {
                  Object y = new Runnable() {
                      public void run() {
                        System.out.println(\"magic\");
                      }
                    };
                }
              };
          }

        }"
      in

      let ast = Common2.with_tmp_file
                  ~str:thecode
                  ~ext:"java"
                  Parse_java.parse_program in

      vis (AProgram ast);

      OUnit.assert_equal ~msg:"Expecting two anonymous class definitions"
        2 !count;

    );
  ]

OCaml

Innovation. Community. Security.