<commit_before>/*
 *  Copyright (C) 2011-2012 The Animo Project
 *  http://animotron.org
 *  	
 *  This file is part of Animotron.
 *  
 *  Animotron is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as 
 *  published by the Free Software Foundation, either version 3 of 
 *  the License, or (at your option) any later version.
 *  
 *  Animotron is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *  
 *  You should have received a copy of 
 *  the GNU Affero General Public License along with Animotron.  
 *  If not, see <http://www.gnu.org/licenses/>.
 */
package org.animotron.games.web;

import org.animotron.ATest;
import org.animotron.expression.Expression;
import org.animotron.expression.JExpression;
import org.animotron.statement.compare.WITH;
import org.animotron.statement.operator.AN;
import org.animotron.statement.query.ANY;
import org.animotron.statement.query.GET;
import org.junit.Test;

import static org.animotron.expression.AnimoExpression.__;
import static org.animotron.expression.JExpression._;
import static org.animotron.expression.JExpression.value;


/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 *
 */
public class CurrentGetWebFrameworkTest extends ATest {

    private Expression query(String site, String service) {
        return new JExpression(
                _(ANY._, "site",
                        _(WITH._, "server-name", value(site)),
                        _(AN._, "service", _(AN._, service))
                )
        );
    }

    private Expression mime(Expression query) {
        return new JExpression(_(GET._, "type", _(GET._, "mime-type", _(query))));
    }

    @Test
    public void test() throws Throwable {

        __(
            "the site get service",
            
            "the text-html (mime-type) (type \"text/html\") (extension \"htm\" \"html\")",
            "the html-page (mime-tipe text-html) (\\html (\\head \\title get title) (\\body any layout))",

            "the main any root",
            "the hello-foo (html-page) (foo, root) (title \"hello foo\") (content \"foo foo foo\")",
            "the hello-bar (html-page) (bar, root) (title \"hello bar\") (content \"bar bar bar\")",
            
            "the zzz-service (html-page) (use zzz) (title \"hello zzz\") (content \"zzz zzz zzz\")",
            "the yyy-service (html-page) (use yyy) (title \"hello yyy\") (content \"yyy yyy yyy\")",

            "the foo-root-layout (layout, foo, root) (\\h1 get title) (\\p get content)",
            "the bar-root-layout (layout, bar, root) (\\h2 get title) (\\div get content)",
            
            "the qLayout (layout, zzz, yyy) (\\h3 get title) (\\span get content)",
            
            "the foo-site (site) (server-name \"foo.com\") (weak-use foo)",
            
            "the bar-site (site) (server-name \"bar.com\") (weak-use bar)", // (bar (yyy-service) (qLayout)).

            "the bar-yyy-service (yyy-service, bar)",
            "the bar-yyy-layout (qLayout, bar)",
            
            "the uri"

        );

        //root service
        Expression fooRoot = query("foo.com", "main");
        //this service wasn't defined, so root should be returned?
        //No!
        Expression fooXxx = query("foo.com", "xxx");
        //this service defined, but do not allowed by site 
        Expression fooYyy = query("foo.com", "yyy");

        Expression barRoot = query("bar.com", "main");
        Expression barZzz = query("bar.com", "zzz");
        Expression barYyy = query("bar.com", "yyy");

        Expression barURI = query("bar.com", "uri");

        assertStringResult(mime(fooRoot), "text/html");
        assertStringResult(mime(fooXxx), "");
        assertStringResult(mime(fooYyy), "");
        assertStringResult(mime(barRoot), "text/html");
        assertStringResult(mime(barZzz), "");
        assertStringResult(mime(barYyy), "");
        assertStringResult(mime(barURI), "");

        assertHtmlResult(fooRoot,
    		"<html><head><title>hello foo</title></head><body><h1>hello foo</h1><p>foo foo foo</p></body></html>");<commit_msg>yet another test<commit_after>/*
 *  Copyright (C) 2011-2012 The Animo Project
 *  http://animotron.org
 *  	
 *  This file is part of Animotron.
 *  
 *  Animotron is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as 
 *  published by the Free Software Foundation, either version 3 of 
 *  the License, or (at your option) any later version.
 *  
 *  Animotron is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *  
 *  You should have received a copy of 
 *  the GNU Affero General Public License along with Animotron.  
 *  If not, see <http://www.gnu.org/licenses/>.
 */
package org.animotron.games.web;

import org.animotron.ATest;
import org.animotron.expression.Expression;
import org.animotron.expression.JExpression;
import org.animotron.statement.compare.WITH;
import org.animotron.statement.query.ANY;
import org.animotron.statement.query.GET;
import org.animotron.statement.relation.USE;
import org.junit.Test;

import static org.animotron.expression.AnimoExpression.__;
import static org.animotron.expression.JExpression._;
import static org.animotron.expression.JExpression.value;


/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 *
 */
public class CurrentGetWebFrameworkTest extends ATest {

    private Expression query(String site, String service) {
        return new JExpression(
                _(ANY._, "service",
                        _(WITH._, "server-name", value(site)),
                        _(USE._, service)
                )
        );
    }

    private Expression mime(Expression query) {
        return new JExpression(_(GET._, "type", _(GET._, "mime-type", _(query))));
    }

    @Test
    public void test() throws Throwable {

        __(
            "the foo-site (site) (server-name \"foo.com\") (weak-use foo) (service zzz)",
            "the bar-site (site) (server-name \"bar.com\") (weak-use bar) (service yyy)",

            "the text-html (mime-type) (type \"text/html\") (extension \"htm\" \"html\")",
            "the html-page (mime-tipe text-html) (\\html (\\head \\title get title) (\\body any layout))",

            "the hello-foo (html-page) (foo-site, root) (title \"hello foo\") (content \"foo foo foo\")",
            "the hello-bar (html-page) (bar-site, root) (title \"hello bar\") (content \"bar bar bar\")",
            
            "the zzz (html-page) (title \"hello zzz\") (content \"zzz zzz zzz\")",
            "the yyy (html-page) (title \"hello yyy\") (content \"yyy yyy yyy\")",

            "the foo-root-layout (layout, foo, root) (\\h1 get title) (\\p get content)",
            "the bar-root-layout (layout, bar, root) (\\h2 get title) (\\div get content)",
            
            "the qLayout (layout, zzz, yyy) (\\h3 get title) (\\span get content)"

        );

        //root service
        Expression fooRoot = query("foo.com", "root");
        //this service wasn't defined, so root should be returned?
        //No!
        Expression fooXxx = query("foo.com", "xxx");
        //this service defined, but do not allowed by site 
        Expression fooYyy = query("foo.com", "yyy");

        Expression barRoot = query("bar.com", "root");
        Expression barZzz = query("bar.com", "zzz");
        Expression barYyy = query("bar.com", "yyy");

        Expression barURI = query("bar.com", "uri");

        assertStringResult(mime(fooRoot), "text/html");
        assertStringResult(mime(fooXxx), "");
        assertStringResult(mime(fooYyy), "");
        assertStringResult(mime(barRoot), "text/html");
        assertStringResult(mime(barZzz), "");
        assertStringResult(mime(barYyy), "");
        assertStringResult(mime(barURI), "");

        assertHtmlResult(fooRoot,
    		"<html><head><title>hello foo</title></head><body><h1>hello foo</h1><p>foo foo foo</p></body></html>");
{'fraction_non_alphanumeric': 0.1465405085748078, 'fraction_numerical': 0.0033116499112950917, 'mean_word_length': 2.587611370386084, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3836203', 'n_tokens_mistral': 2610, 'n_tokens_neox': 2532, 'n_words': 750}