<commit_before>#!/usr/bin/env python3

import sys, os, unittest, logging, pkg_resources

# Extend PYTHONPATH with local 'lib' folder
jasyroot = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), os.pardir, os.pardir, os.pardir))
sys.path.insert(0, jasyroot)


import jasy.js.parse.Parser as Parser
import jasy.js.parse.ScopeScanner as ScopeScanner
import jasy.js.api.Data as Data


class Tests(unittest.TestCase):

    def process(self, code):
        node = Parser.parse(code)
        ScopeScanner.scan(node)
        data = Data.ApiData(node, "test")
        
        return data
        
    
    def test_uses(self):
        
        data = self.process("""

        core.Class("foo.Bar", {
        
            main: function() {
                
                document.body.appendChild(new Image());
            
            }
        
        });

        """)

        self.assertIsInstance(data, Data.ApiData)
        
        self.assertIn("Image", data.main["uses"])
        self.assertIn("document", data.main["uses"])
        self.assertIn("document.body.appendChild", data.main["uses"])
        self.assertIn("core", data.main["uses"])
        self.assertIn("core.Class", data.main["uses"])
        
        
    def test_basic(self):

        data = self.process("""

        core.Class("foo.Bar", {});

        """)

        self.assertIsInstance(data, Data.ApiData)
        
                
    def test_primitives(self):
        
        data = self.process("""
        
        core.Class("foo.Bar", 
        {
          members: {
            pi: 3.14,
            str: "hello world",
            bool: true
          }<commit_msg>Added test for usage<commit_after>#!/usr/bin/env python3

import sys, os, unittest, logging, pkg_resources

# Extend PYTHONPATH with local 'lib' folder
jasyroot = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), os.pardir, os.pardir, os.pardir))
sys.path.insert(0, jasyroot)


import jasy.js.parse.Parser as Parser
import jasy.js.parse.ScopeScanner as ScopeScanner
import jasy.js.api.Data as Data


class Tests(unittest.TestCase):

    def process(self, code):
        node = Parser.parse(code)
        ScopeScanner.scan(node)
        data = Data.ApiData(node, "test")
        
        return data
        
    
    def test_uses(self):
        
        data = self.process("""

        core.Class("foo.Bar", {
        
            main: function() {
                
                document.body.appendChild(new Image());
            
            }
        
        });

        """)

        self.assertIsInstance(data, Data.ApiData)
        
        self.assertIn("Image", data.main["uses"])
        self.assertIn("document", data.main["uses"])
        self.assertIn("document.body.appendChild", data.main["uses"])
        self.assertIn("core", data.main["uses"])
        self.assertIn("core.Class", data.main["uses"])
        
        
    def test_line(self):
        
        data = self.process("""
        
        /**
         * Class comment
         */
        core.Class("foo.Bar", {
        
        
        });
        """)

        self.assertIsInstance(data, Data.ApiData)
        
        print(data.main.line)
        
        
    def test_basic(self):

        data = self.process("""

        core.Class("foo.Bar", {});

        """)

        self.assertIsInstance(data, Data.ApiData)
        
                
    def test_primitives(self):
        
        data = self.process("""
        
        core.Class("foo.Bar", 
        {
          members: {
            pi: 3.14,
            str: "hello world",
            bool: true
          }
{'fraction_non_alphanumeric': 0.13468938977460143, 'fraction_numerical': 0.003298515667949423, 'mean_word_length': 1.629335260115607, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2707762', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1092, 'n_words': 187}