@@ -1812,6 +1812,88 @@ def test_toctree() -> None:
18121812 )
18131813
18141814
1815+ def test_mongo_web_shell () -> None :
1816+ path = ROOT_PATH .joinpath (Path ("test.rst" ))
1817+ project_config = ProjectConfig (ROOT_PATH , "" , source = "./" )
1818+ parser = rstparser .Parser (project_config , JSONVisitor )
1819+
1820+ # Test simple use of mongo-web-shell directive
1821+ page , diagnostics = parse_rst (
1822+ parser ,
1823+ path ,
1824+ """
1825+ .. mongo-web-shell::
1826+ """ ,
1827+ )
1828+ page .finish (diagnostics )
1829+ assert diagnostics == []
1830+ check_ast_testing_string (
1831+ page .ast ,
1832+ """<root>
1833+ <directive domain="mongodb" name="mongo-web-shell"/>
1834+ </root>""" ,
1835+ )
1836+
1837+ # Test with option
1838+ page , diagnostics = parse_rst (
1839+ parser ,
1840+ path ,
1841+ """
1842+ .. mongo-web-shell::
1843+ :version: 4.2
1844+ """ ,
1845+ )
1846+ page .finish (diagnostics )
1847+ assert diagnostics == []
1848+ check_ast_testing_string (
1849+ page .ast ,
1850+ """<root>
1851+ <directive domain="mongodb" name="mongo-web-shell" version="4.2"/>
1852+ </root>""" ,
1853+ )
1854+
1855+ # Test with invalid version
1856+ page , diagnostics = parse_rst (
1857+ parser ,
1858+ path ,
1859+ """
1860+ .. mongo-web-shell::
1861+ :version: 4.1
1862+ """ ,
1863+ )
1864+ page .finish (diagnostics )
1865+ assert len (diagnostics ) == 1
1866+ assert isinstance (diagnostics [0 ], DocUtilsParseError )
1867+
1868+ # Test unknown options
1869+ page , diagnostics = parse_rst (
1870+ parser ,
1871+ path ,
1872+ """
1873+ .. mongo-web-shell::
1874+ :width: 100%
1875+ :height: 300
1876+ """ ,
1877+ )
1878+ page .finish (diagnostics )
1879+ assert len (diagnostics ) == 1
1880+ assert isinstance (diagnostics [0 ], DocUtilsParseError )
1881+
1882+ # Test with unwanted content block
1883+ page , diagnostics = parse_rst (
1884+ parser ,
1885+ path ,
1886+ """
1887+ .. mongo-web-shell::
1888+
1889+ Hello world. This is unwanted content.
1890+ """ ,
1891+ )
1892+ page .finish (diagnostics )
1893+ assert len (diagnostics ) == 1
1894+ assert isinstance (diagnostics [0 ], DocUtilsParseError )
1895+
1896+
18151897def test_callable_target () -> None :
18161898 path = ROOT_PATH .joinpath (Path ("test.rst" ))
18171899 project_config = ProjectConfig (ROOT_PATH , "" , source = "./" )
0 commit comments