<commit_before>var csproj  = require('../../src/util/csproj'),
    path    = require('path'),
    os      = require('osenv'),
    et      = require('elementtree'),
    fs      = require('fs'),
    xml_helpers = require('../../src/util/xml-helpers');

var wp7_project     = path.join(__dirname, '..', 'projects', 'wp7'),
    temp            = path.join(os.tmpdir(), 'plugman'),
    example_csproj  = path.join(wp7_project, 'CordovaAppProj.csproj'),
    wpcsproj        = path.join(__dirname, '..', 'plugins', 'WPcsproj');

describe('csproj', function() {
    it('should throw if passed in an invalid xml file path ref', function() {
        expect(function() {
            new csproj('blahblah');
        }).toThrow();
    });
    it('should successfully parse a valid csproj file into an xml document', function() {
        var doc;
        expect(function() {
            doc = new csproj(example_csproj);
        }).not.toThrow();
        expect(doc.xml.getroot()).toBeDefined();
    });

    describe('write method', function() {
        
    });

    describe('source file', function() {
        var test_csproj = new csproj(example_csproj);
        var page_test   = path.join('src', 'UI', 'PageTest.xaml');
        var page_test_cs = path.join('src', 'UI', 'PageTest.xaml.cs');
        var lib_test    = path.join('lib', 'LibraryTest.dll');
        var file_test   = path.join('src', 'FileTest.cs');

        describe('add method', function() {

            it('should properly add .xaml files', function() {
                test_csproj.addSourceFile(page_test);
                expect(test_csproj.xml.getroot().find('.//Page[@Include="src\\UI\\PageTest.xaml"]')).toBeTruthy();        
                expect(test_csproj.xml.getroot().find('.//Page[@Include="src\\UI\\PageTest.xaml"]/Generator').text).toEqual('MSBuild:Compile');
                expect(test_csproj.xml.getroot().find('.//Page[@Include="src\\UI\\PageTest.xaml"]/SubType').text).toEqual('Designer');
            });
            it('should properly add .xaml.cs files', function() {
                test_csproj.addSourceFile(page_test_cs);
                expect(test_csproj.xml.getroot().find('.//Compile[@Include="src\\UI\\PageTest.xaml.cs"]')).toBeTruthy();
                expect(test_csproj.xml.getroot().find('.//Compile[@Include="src\\UI\\PageTest.xaml.cs"]/DependentUpon').text).toEqual('PageTest.xaml');
            });
            it('should properly add .dll references', function() {
                test_csproj.addSourceFile(lib_test);
                expect(test_csproj.xml.getroot().find('.//Reference[@Include="LibraryTest"]')).toBeTruthy();
                expect(test_csproj.xml.getroot().find('.//Reference[@Include="LibraryTest"]/HintPath').text).toEqual('lib\\LibraryTest.dll');
            });
            it('should properly add .cs files', function() {
                test_csproj.addSourceFile(file_test);
                expect(test_csproj.xml.getroot().find('.//Compile[@Include="src\\FileTest.cs"]')).toBeTruthy();
            });

        });

        describe('remove method', function() {

            it('should properly remove .xaml pages', function() {
                test_csproj.removeSourceFile(page_test);
                expect(test_csproj.xml.getroot().find('.//Page[@Include="src\\UI\\PageTest.xaml"]')).toBeFalsy();
            });
            it('should properly remove .xaml.cs files', function() {
                test_csproj.removeSourceFile(page_test_cs);
                expect(test_csproj.xml.getroot().find('.//Compile[@Include="src\\UI\\PageTest.xaml.cs"]')).toBeFalsy();
            });
            it('should properly remove .dll references', function() {
                test_csproj.removeSourceFile(lib_test);
                expect(test_csproj.xml.getroot().find('.//Reference[@Include="LibraryTest"]')).toBeFalsy();
            });
            it('should properly remove .cs files', function() {
                test_csproj.removeSourceFile(file_test);
                expect(test_csproj.xml.getroot().find('.//Compile[@Include="src\\FileTest.cs"]')).toBeFalsy();
            });
            it('should remove all empty ItemGroup\'s', function() {
                test_csproj.removeSourceFile(page_test);
                test_csproj.removeSourceFile(page_test_cs);
                test_csproj.removeSourceFile(lib_test);
                test_csproj.removeSourceFile(file_test);
                var item_groups = test_csproj.xml.findall('ItemGroup');
                for (var i = 0, l = item_groups.length; i < l; i++) {
                    var group = item_groups[i];
                    expect(group._children.length).toBeGreaterThan(0);
                }
            })

        });
    });
});
<commit_msg>added tests for adding/removing Conent refereces to csproj file<commit_after>var csproj  = require('../../src/util/csproj'),
    path    = require('path'),
    os      = require('osenv'),
    et      = require('elementtree'),
    fs      = require('fs'),
    xml_helpers = require('../../src/util/xml-helpers');

var wp7_project     = path.join(__dirname, '..', 'projects', 'wp7'),
    temp            = path.join(os.tmpdir(), 'plugman'),
    example_csproj  = path.join(wp7_project, 'CordovaAppProj.csproj'),
    wpcsproj        = path.join(__dirname, '..', 'plugins', 'WPcsproj');

describe('csproj', function() {
    it('should throw if passed in an invalid xml file path ref', function() {
        expect(function() {
            new csproj('blahblah');
        }).toThrow();
    });
    it('should successfully parse a valid csproj file into an xml document', function() {
        var doc;
        expect(function() {
            doc = new csproj(example_csproj);
        }).not.toThrow();
        expect(doc.xml.getroot()).toBeDefined();
    });

    describe('write method', function() {
        
    });

    describe('source file', function() {
        var test_csproj = new csproj(example_csproj);
        var page_test   = path.join('src', 'UI', 'PageTest.xaml');
        var page_test_cs = path.join('src', 'UI', 'PageTest.xaml.cs');
        var lib_test    = path.join('lib', 'LibraryTest.dll');
        var file_test   = path.join('src', 'FileTest.cs');
        var content_test   = path.join('src', 'Content.img');

        describe('add method', function() {

            it('should properly add .xaml files', function() {
                test_csproj.addSourceFile(page_test);
                expect(test_csproj.xml.getroot().find('.//Page[@Include="src\\UI\\PageTest.xaml"]')).toBeTruthy();        
                expect(test_csproj.xml.getroot().find('.//Page[@Include="src\\UI\\PageTest.xaml"]/Generator').text).toEqual('MSBuild:Compile');
                expect(test_csproj.xml.getroot().find('.//Page[@Include="src\\UI\\PageTest.xaml"]/SubType').text).toEqual('Designer');
            });
            it('should properly add .xaml.cs files', function() {
                test_csproj.addSourceFile(page_test_cs);
                expect(test_csproj.xml.getroot().find('.//Compile[@Include="src\\UI\\PageTest.xaml.cs"]')).toBeTruthy();
                expect(test_csproj.xml.getroot().find('.//Compile[@Include="src\\UI\\PageTest.xaml.cs"]/DependentUpon').text).toEqual('PageTest.xaml');
            });
            it('should properly add .dll references', function() {
                test_csproj.addSourceFile(lib_test);
                expect(test_csproj.xml.getroot().find('.//Reference[@Include="LibraryTest"]')).toBeTruthy();
                expect(test_csproj.xml.getroot().find('.//Reference[@Include="LibraryTest"]/HintPath').text).toEqual('lib\\LibraryTest.dll');
            });
            it('should properly add .cs files', function() {
                test_csproj.addSourceFile(file_test);
                expect(test_csproj.xml.getroot().find('.//Compile[@Include="src\\FileTest.cs"]')).toBeTruthy();
            });
            it('should properly add content files', function() {
                test_csproj.addSourceFile(content_test);
                expect(test_csproj.xml.getroot().find('.//Content[@Include="src\\Content.img"]')).toBeTruthy();
            });

        });

        describe('remove method', function() {

            it('should properly remove .xaml pages', function() {
                test_csproj.removeSourceFile(page_test);
                expect(test_csproj.xml.getroot().find('.//Page[@Include="src\\UI\\PageTest.xaml"]')).toBeFalsy();
            });
            it('should properly remove .xaml.cs files', function() {
                test_csproj.removeSourceFile(page_test_cs);
                expect(test_csproj.xml.getroot().find('.//Compile[@Include="src\\UI\\PageTest.xaml.cs"]')).toBeFalsy();
            });
            it('should properly remove .dll references', function() {
                test_csproj.removeSourceFile(lib_test);
                expect(test_csproj.xml.getroot().find('.//Reference[@Include="LibraryTest"]')).toBeFalsy();
            });
            it('should properly remove .cs files', function() {
                test_csproj.removeSourceFile(file_test);
                expect(test_csproj.xml.getroot().find('.//Compile[@Include="src\\FileTest.cs"]')).toBeFalsy();
            });
            it('should properly remove content files', function() {
                test_csproj.removeSourceFile(content_test);
                expect(test_csproj.xml.getroot().find('.//Content[@Include="src\\Content.img"]')).toBeFalsy();
            });
            it('should remove all empty ItemGroup\'s', function() {
                test_csproj.removeSourceFile(page_test);
                test_csproj.removeSourceFile(page_test_cs);
                test_csproj.removeSourceFile(lib_test);
                test_csproj.removeSourceFile(file_test);
                var item_groups = test_csproj.xml.findall('ItemGroup');
                for (var i = 0, l = item_groups.length; i < l; i++) {
                    var group = item_groups[i];
                    expect(group._children.length).toBeGreaterThan(0);
                }
            })

        });
    });
});

{'fraction_non_alphanumeric': 0.16968976112597878, 'fraction_numerical': 0.000991178511249876, 'mean_word_length': 2.304945954798559, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 38}, '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': '1326168', 'n_tokens_mistral': 3034, 'n_tokens_neox': 2876, 'n_words': 416}