123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990openCommonmoduleE=Entity_codeopenOUnit(*****************************************************************************)(* Prelude *)(*****************************************************************************)(*****************************************************************************)(* Unit tests *)(*****************************************************************************)(*---------------------------------------------------------------------------*)(* Annotations *)(*---------------------------------------------------------------------------*)letannotation_unittest="annotation_js">:::["commonjs annotations">::(fun()->letfile_content="
/**
* @providesModule my-module
*/
function foo() {}
/**
* @providesLegacy other-module
*/
function bar() {}
"inCommon2.with_tmp_file~str:file_content~ext:"js"(funtmpfile->let(ast_and_tokens,_stat)=Parse_js.parsetmpfileinletannots=Annotation_js.annotations_of_program_with_commentsast_and_tokens|>List.mapfstinassert_equal~msg:"it should extract @providesModule annotations"[Annotation_js.ProvidesModule"my-module";Annotation_js.ProvidesLegacy"other-module";]annots));](*---------------------------------------------------------------------------*)(* Tags *)(*---------------------------------------------------------------------------*)lettags_unittest="tags_js">:::["commonjs tags support">::(fun()->letfile_content="
/**
* @providesModule my-module
*/
function foo() {}
"inCommon2.with_tmp_file~str:file_content~ext:"js"(funtmpfile->lettags=Tags_js.tags_of_files_or_dirs~verbose:false[tmpfile]in(matchtags|>List.mapsnd|>List.flattenwith|[{Tags_file.tagname="my-module";kind=E.Module;_}]->()|_->assert_failure"it should extract module names from comments");lettmpfile=Common.new_temp_file"unit""tags"inTags_file.generate_vi_tags_filetmpfiletags;letcontent=Common.read_filetmpfileinifcontent=~"my-module\t.*\t/\\(.*\\)/;.*"thenletstr=Common.matched1contentinassert_equal~msg:"it should correctly escape slash in vi tags file""\\/**"strelseassert_failure"it should generate the write vi tags file"));](*---------------------------------------------------------------------------*)(* Final suite *)(*---------------------------------------------------------------------------*)letunittest="analyze_js">:::[annotation_unittest;tags_unittest;]