1+ use std:: path:: PathBuf ;
2+
3+ use lsp_types:: { DiagnosticSeverity , NumberOrString } ;
4+ use odoo_ls_server:: { S , utils:: PathSanitizer } ;
5+
6+ use crate :: { setup:: setup:: * , test_utils:: { diag_on_line, verify_diagnostics_against_doc} } ;
7+
8+ #[ test]
9+ fn test_ols05000_2_3_py_file ( ) {
10+ let ( mut odoo, config) = setup_server ( true ) ;
11+ let mut session = create_init_session ( & mut odoo, config) ;
12+ let test_addons_path = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "tests" ) . join ( "data" ) . join ( "addons" ) ;
13+ let bikes_py_path = test_addons_path. join ( "module_for_diagnostics" ) . join ( "models" ) . join ( "bike_parts_wheel.py" ) ;
14+ assert ! ( PathBuf :: from( & bikes_py_path) . exists( ) , "Test file does not exist: {}" , bikes_py_path. display( ) ) ;
15+ let bikes_py_diagnostics = get_diagnostics_for_path ( & mut session, & bikes_py_path. sanitize ( ) ) ;
16+ let doc_diags = get_diagnostics_test_comments ( & mut session, & bikes_py_path. sanitize ( ) ) ;
17+ verify_diagnostics_against_doc ( bikes_py_diagnostics, doc_diags) ; // OLS05002 & OLS05003
18+ }
19+ #[ test]
20+ fn test_ols050000_to50012_xml_file ( ) {
21+ let ( mut odoo, config) = setup_server ( true ) ;
22+ let mut session = create_init_session ( & mut odoo, config) ;
23+ let test_addons_path = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "tests" ) . join ( "data" ) . join ( "addons" ) ;
24+ let bikes_xml_path = test_addons_path. join ( "module_for_diagnostics" ) . join ( "data" ) . join ( "bikes.xml" ) ;
25+ assert ! ( PathBuf :: from( & bikes_xml_path) . exists( ) , "Test file does not exist: {}" , bikes_xml_path. display( ) ) ;
26+ let bikes_xml_diagnostics = get_diagnostics_for_path ( & mut session, & bikes_xml_path. sanitize ( ) ) ;
27+ // OLS05001 - Disabled TODO: Re-enable when OLS05001 is implemented
28+ // OLS05003
29+ let ols50003_diagnostics = diag_on_line ( & bikes_xml_diagnostics, 25 ) ;
30+ assert_eq ! ( ols50003_diagnostics. len( ) , 1 ) ;
31+ let diag = & ols50003_diagnostics[ 0 ] ;
32+ assert ! ( diag. code. is_some( ) ) ;
33+ let code = match & diag. code {
34+ Some ( NumberOrString :: String ( code) ) => code,
35+ Some ( NumberOrString :: Number ( num) ) => panic ! ( "Unexpected numeric code: {}" , num) ,
36+ None => panic ! ( "Diagnostic code is None" ) ,
37+ } ;
38+ assert ! ( code == & S !( "OLS05003" ) ) ;
39+ assert ! ( diag. severity. is_some_and( |s| s == DiagnosticSeverity :: ERROR ) ) ;
40+
41+ // OLS05004
42+ let ols50004_diagnostics = diag_on_line ( & bikes_xml_diagnostics, 36 ) ;
43+ assert_eq ! ( ols50004_diagnostics. len( ) , 1 ) ;
44+ let diag = & ols50004_diagnostics[ 0 ] ;
45+ assert ! ( diag. code. is_some( ) ) ;
46+ let code = match & diag. code {
47+ Some ( NumberOrString :: String ( code) ) => code,
48+ Some ( NumberOrString :: Number ( num) ) => panic ! ( "Unexpected numeric code: {}" , num) ,
49+ None => panic ! ( "Diagnostic code is None" ) ,
50+ } ;
51+ assert ! ( code == & S !( "OLS05004" ) ) ;
52+ assert ! ( diag. severity. is_some_and( |s| s == DiagnosticSeverity :: ERROR ) ) ;
53+
54+ // OLS05005
55+ let ols50005_diagnostics = diag_on_line ( & bikes_xml_diagnostics, 38 ) ;
56+ assert_eq ! ( ols50005_diagnostics. len( ) , 1 ) ;
57+ let diag = & ols50005_diagnostics[ 0 ] ;
58+ assert ! ( diag. code. is_some( ) ) ;
59+ let code = match & diag. code {
60+ Some ( NumberOrString :: String ( code) ) => code,
61+ Some ( NumberOrString :: Number ( num) ) => panic ! ( "Unexpected numeric code: {}" , num) ,
62+ None => panic ! ( "Diagnostic code is None" ) ,
63+ } ;
64+ assert ! ( code == & S !( "OLS05005" ) ) ;
65+ assert ! ( diag. severity. is_some_and( |s| s == DiagnosticSeverity :: ERROR ) ) ;
66+
67+ // OLS05006
68+ let ols50006_diagnostics = diag_on_line ( & bikes_xml_diagnostics, 39 ) ;
69+ assert_eq ! ( ols50006_diagnostics. len( ) , 1 ) ;
70+ let diag = & ols50006_diagnostics[ 0 ] ;
71+ assert ! ( diag. code. is_some( ) ) ;
72+ let code = match & diag. code {
73+ Some ( NumberOrString :: String ( code) ) => code,
74+ Some ( NumberOrString :: Number ( num) ) => panic ! ( "Unexpected numeric code: {}" , num) ,
75+ None => panic ! ( "Diagnostic code is None" ) ,
76+ } ;
77+ assert ! ( code == & S !( "OLS05006" ) ) ;
78+ assert ! ( diag. severity. is_some_and( |s| s == DiagnosticSeverity :: ERROR ) ) ;
79+
80+ // OLS05007
81+ let ols50007_diagnostics = diag_on_line ( & bikes_xml_diagnostics, 40 ) ;
82+ assert_eq ! ( ols50007_diagnostics. len( ) , 1 ) ;
83+ let diag = & ols50007_diagnostics[ 0 ] ;
84+ assert ! ( diag. code. is_some( ) ) ;
85+ let code = match & diag. code {
86+ Some ( NumberOrString :: String ( code) ) => code,
87+ Some ( NumberOrString :: Number ( num) ) => panic ! ( "Unexpected numeric code: {}" , num) ,
88+ None => panic ! ( "Diagnostic code is None" ) ,
89+ } ;
90+ assert ! ( code == & S !( "OLS05007" ) ) ;
91+ assert ! ( diag. severity. is_some_and( |s| s == DiagnosticSeverity :: ERROR ) ) ;
92+
93+ // OLS05008
94+ let ols50008_diagnostics = diag_on_line ( & bikes_xml_diagnostics, 41 ) ;
95+ assert_eq ! ( ols50008_diagnostics. len( ) , 1 ) ;
96+ let diag = & ols50008_diagnostics[ 0 ] ;
97+ assert ! ( diag. code. is_some( ) ) ;
98+ let code = match & diag. code {
99+ Some ( NumberOrString :: String ( code) ) => code,
100+ Some ( NumberOrString :: Number ( num) ) => panic ! ( "Unexpected numeric code: {}" , num) ,
101+ None => panic ! ( "Diagnostic code is None" ) ,
102+ } ;
103+ assert ! ( code == & S !( "OLS05008" ) ) ;
104+ assert ! ( diag. severity. is_some_and( |s| s == DiagnosticSeverity :: ERROR ) ) ;
105+
106+ // OLS05009
107+ let ols50009_diagnostics = diag_on_line ( & bikes_xml_diagnostics, 43 ) ;
108+ assert_eq ! ( ols50009_diagnostics. len( ) , 1 ) ;
109+ let diag = & ols50009_diagnostics[ 0 ] ;
110+ assert ! ( diag. code. is_some( ) ) ;
111+ let code = match & diag. code {
112+ Some ( NumberOrString :: String ( code) ) => code,
113+ Some ( NumberOrString :: Number ( num) ) => panic ! ( "Unexpected numeric code: {}" , num) ,
114+ None => panic ! ( "Diagnostic code is None" ) ,
115+ } ;
116+ assert ! ( code == & S !( "OLS05009" ) ) ;
117+ assert ! ( diag. severity. is_some_and( |s| s == DiagnosticSeverity :: ERROR ) ) ;
118+
119+ // OLS05010
120+ let ols50010_diagnostics = diag_on_line ( & bikes_xml_diagnostics, 42 ) ;
121+ assert_eq ! ( ols50010_diagnostics. len( ) , 1 ) ;
122+ let diag = & ols50010_diagnostics[ 0 ] ;
123+ assert ! ( diag. code. is_some( ) ) ;
124+ let code = match & diag. code {
125+ Some ( NumberOrString :: String ( code) ) => code,
126+ Some ( NumberOrString :: Number ( num) ) => panic ! ( "Unexpected numeric code: {}" , num) ,
127+ None => panic ! ( "Diagnostic code is None" ) ,
128+ } ;
129+ assert ! ( code == & S !( "OLS05010" ) ) ;
130+ assert ! ( diag. severity. is_some_and( |s| s == DiagnosticSeverity :: ERROR ) ) ;
131+
132+ // OLS05011
133+ let ols50011_diagnostics = diag_on_line ( & bikes_xml_diagnostics, 45 ) ;
134+ assert_eq ! ( ols50011_diagnostics. len( ) , 1 ) ;
135+ let diag = & ols50011_diagnostics[ 0 ] ;
136+ assert ! ( diag. code. is_some( ) ) ;
137+ let code = match & diag. code {
138+ Some ( NumberOrString :: String ( code) ) => code,
139+ Some ( NumberOrString :: Number ( num) ) => panic ! ( "Unexpected numeric code: {}" , num) ,
140+ None => panic ! ( "Diagnostic code is None" ) ,
141+ } ;
142+ assert ! ( code == & S !( "OLS05011" ) ) ;
143+ assert ! ( diag. severity. is_some_and( |s| s == DiagnosticSeverity :: ERROR ) ) ;
144+
145+ // OLS05012
146+ let ols50012_diagnostics = diag_on_line ( & bikes_xml_diagnostics, 48 ) ;
147+ assert_eq ! ( ols50012_diagnostics. len( ) , 1 ) ;
148+ let diag = & ols50012_diagnostics[ 0 ] ;
149+ assert ! ( diag. code. is_some( ) ) ;
150+ let code = match & diag. code {
151+ Some ( NumberOrString :: String ( code) ) => code,
152+ Some ( NumberOrString :: Number ( num) ) => panic ! ( "Unexpected numeric code: {}" , num) ,
153+ None => panic ! ( "Diagnostic code is None" ) ,
154+ } ;
155+ assert ! ( code == & S !( "OLS05012" ) ) ;
156+ assert ! ( diag. severity. is_some_and( |s| s == DiagnosticSeverity :: ERROR ) ) ;
157+ }
0 commit comments